Unified · Split
| @@ -1,4 +1,4 @@ | ||
| 1 | −# styx.py - Classes to decode and encode Styx (9P2000) messages. | |
| 1 | +# styxserver.py - Network code for handling Styx (9P2000) messages. | |
| 2 | 2 | # |
| 3 | 3 | # Copyright (C) 2018 David Boddie <david@boddie.org.uk> |
| 4 | 4 | # |
| @@ -74,6 +74,9 @@ class StyxServer: · 69 unmodified lines | ||
| 74 | 74 | store = self.clients[client] |
| 75 | 75 | |
| 76 | 76 | s = store.stat(msg.fid) |
| 77 | + if s == None: | |
| 78 | + return styx.Rerror(msg.tag, "Not found.") | |
| 79 | + | |
| 77 | 80 | return styx.Rstat(msg.tag, s) |
| 78 | 81 | |
| 79 | 82 | def Twalk(self, conn, client, msg): |
| @@ -87,25 +90,26 @@ class StyxServer: · 7 unmodified lines | ||
| 87 | 90 | # path corresponding to the current fid. |
| 88 | 91 | qids = [] |
| 89 | 92 | new_path = path.split("/") |
| 90 | − try: | |
| 91 | − for element in msg.wname: | |
| 93 | + | |
| 94 | + for element in msg.wname: | |
| 95 | + | |
| 96 | + if element == "..": | |
| 97 | + # Handle parent directories as path elements. | |
| 98 | + if new_path: new_path.pop() | |
| 99 | + else: | |
| 100 | + new_path.append(element) | |
| 101 | + | |
| 102 | + # Update the qid variable, create qids for each intermediate | |
| 103 | + # path, and record the qids created. | |
| 104 | + qid = store.make_qid("/".join(new_path)) | |
| 92 | 105 | |
| 93 | − if element == "..": | |
| 94 | − # Handle parent directories as path elements. | |
| 95 | − if new_path: new_path.pop() | |
| 106 | + if qid == None: | |
| 107 | + if len(qids) > 0: | |
| 108 | + return styx.Rwalk(msg.tag, qids) | |
| 96 | 109 | else: |
| 97 | − new_path.append(element) | |
| 98 | − | |
| 99 | − # Update the qid variable, create qids for each intermediate | |
| 100 | − # path, and record the qids created. | |
| 101 | − qid = store.make_qid("/".join(new_path)) | |
| 102 | − qids.append(qid) | |
| 103 | − | |
| 104 | − except OSError: | |
| 105 | − if len(qids) > 0: | |
| 106 | − return styx.Rwalk(msg.tag, qids) | |
| 107 | − else: | |
| 108 | − return styx.Rerror(msg.tag, "Not found.") | |
| 110 | + return styx.Rerror(msg.tag, "Not found.") | |
| 111 | + | |
| 112 | + qids.append(qid) | |
| 109 | 113 | |
| 110 | 114 | # Set the qid and path for the newfid passed by the caller. |
| 111 | 115 | store.set_qid_path(msg.newfid, qid, "/".join(new_path)) |
| @@ -158,6 +162,11 @@ class StyxServer: · 46 unmodified lines | ||
| 158 | 162 | # The fid must have an existing qid. |
| 159 | 163 | count = store.write(msg.fid, msg.offset, msg.data) |
| 160 | 164 | |
| 165 | + if count == -1: | |
| 166 | + return styx.Rerror(msg.tag, "Not a file.") | |
| 167 | + elif count != len(msg.data): | |
| 168 | + return styx.Rerror(msg.tag, "Failed to write data.") | |
| 169 | + | |
| 161 | 170 | return styx.Rwrite(msg.tag, count) |
| 162 | 171 | |
| 163 | 172 | def Tclunk(self, conn, client, msg): |
| @@ -201,7 +210,7 @@ class StyxServer: · 37 unmodified lines | ||
| 201 | 210 | |
| 202 | 211 | store = self.clients[client] |
| 203 | 212 | |
| 204 | − s = store.wstat(msg.fid, msg.stat) | |
| 213 | + store.wstat(msg.fid, msg.stat) | |
| 205 | 214 | return styx.Rwstat(msg.tag) |
| 206 | 215 | |
| 207 | 216 | handlers = { |