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 | # Copyright (C) 2018 David Boddie <david@boddie.org.uk> | 3 | # Copyright (C) 2018 David Boddie <david@boddie.org.uk> |
| 4 | # | 4 | # |
| @@ -74,6 +74,9 @@ class StyxServer: · 69 unmodified lines | |||
| 74 | store = self.clients[client] | 74 | store = self.clients[client] |
| 75 | 75 | ||
| 76 | s = store.stat(msg.fid) | 76 | s = store.stat(msg.fid) |
| 77 | if s == None: | ||
| 78 | return styx.Rerror(msg.tag, "Not found.") | ||
| 79 | |||
| 77 | return styx.Rstat(msg.tag, s) | 80 | return styx.Rstat(msg.tag, s) |
| 78 | 81 | ||
| 79 | def Twalk(self, conn, client, msg): | 82 | def Twalk(self, conn, client, msg): |
| @@ -87,25 +90,26 @@ class StyxServer: · 7 unmodified lines | |||
| 87 | # path corresponding to the current fid. | 90 | # path corresponding to the current fid. |
| 88 | qids = [] | 91 | qids = [] |
| 89 | new_path = path.split("/") | 92 | new_path = path.split("/") |
| 90 | try: | 93 | |
| 91 | for element in msg.wname: | 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 == "..": | 106 | if qid == None: |
| 94 | # Handle parent directories as path elements. | 107 | if len(qids) > 0: |
| 95 | if new_path: new_path.pop() | 108 | return styx.Rwalk(msg.tag, qids) |
| 96 | else: | 109 | else: |
| 97 | new_path.append(element) | 110 | return styx.Rerror(msg.tag, "Not found.") |
| 98 | 111 | ||
| 99 | # Update the qid variable, create qids for each intermediate | 112 | qids.append(qid) |
| 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.") | ||
| 109 | 113 | ||
| 110 | # Set the qid and path for the newfid passed by the caller. | 114 | # Set the qid and path for the newfid passed by the caller. |
| 111 | store.set_qid_path(msg.newfid, qid, "/".join(new_path)) | 115 | store.set_qid_path(msg.newfid, qid, "/".join(new_path)) |
| @@ -158,6 +162,11 @@ class StyxServer: · 46 unmodified lines | |||
| 158 | # The fid must have an existing qid. | 162 | # The fid must have an existing qid. |
| 159 | count = store.write(msg.fid, msg.offset, msg.data) | 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 | return styx.Rwrite(msg.tag, count) | 170 | return styx.Rwrite(msg.tag, count) |
| 162 | 171 | ||
| 163 | def Tclunk(self, conn, client, msg): | 172 | def Tclunk(self, conn, client, msg): |
| @@ -201,7 +210,7 @@ class StyxServer: · 37 unmodified lines | |||
| 201 | 210 | ||
| 202 | store = self.clients[client] | 211 | store = self.clients[client] |
| 203 | 212 | ||
| 204 | s = store.wstat(msg.fid, msg.stat) | 213 | store.wstat(msg.fid, msg.stat) |
| 205 | return styx.Rwstat(msg.tag) | 214 | return styx.Rwstat(msg.tag) |
| 206 | 215 | ||
| 207 | handlers = { | 216 | handlers = { |