History

Added checks for missing stat information and invalid qids. Removed OSError handling since this belongs in the local file server example. Added handling of failed write commands and discarded return values from calls to the store's wstat method.

David Boddie committed 8 years ago

Commit b409cc81 parent 7a3325e1 file · +28 −19Browse files

Unified · Split

styxserver.py+28−19
@@ -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.
22 #
33 # Copyright (C) 2018 David Boddie <david@boddie.org.uk>
44 #
@@ -74,6 +74,9 @@ class StyxServer: · 69 unmodified lines
7474 store = self.clients[client]
7575
7676 s = store.stat(msg.fid)
77+ if s == None:
78+ return styx.Rerror(msg.tag, "Not found.")
79+
7780 return styx.Rstat(msg.tag, s)
7881
7982 def Twalk(self, conn, client, msg):
@@ -87,25 +90,26 @@ class StyxServer: · 7 unmodified lines
8790 # path corresponding to the current fid.
8891 qids = []
8992 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))
92105
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)
96109 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)
109113
110114 # Set the qid and path for the newfid passed by the caller.
111115 store.set_qid_path(msg.newfid, qid, "/".join(new_path))
@@ -158,6 +162,11 @@ class StyxServer: · 46 unmodified lines
158162 # The fid must have an existing qid.
159163 count = store.write(msg.fid, msg.offset, msg.data)
160164
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+
161170 return styx.Rwrite(msg.tag, count)
162171
163172 def Tclunk(self, conn, client, msg):
@@ -201,7 +210,7 @@ class StyxServer: · 37 unmodified lines
201210
202211 store = self.clients[client]
203212
204− s = store.wstat(msg.fid, msg.stat)
213+ store.wstat(msg.fid, msg.stat)
205214 return styx.Rwstat(msg.tag)
206215
207216 handlers = {