copyparty 1.13.3__py3-none-any.whl → 1.13.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
copyparty/ftpd.py CHANGED
@@ -19,6 +19,7 @@ from .__init__ import PY2, TYPE_CHECKING
19
19
  from .authsrv import VFS
20
20
  from .bos import bos
21
21
  from .util import (
22
+ VF_CAREFUL,
22
23
  Daemon,
23
24
  ODict,
24
25
  Pebkac,
@@ -30,6 +31,7 @@ from .util import (
30
31
  runhook,
31
32
  sanitize_fn,
32
33
  vjoin,
34
+ wunlink,
33
35
  )
34
36
 
35
37
  if TYPE_CHECKING:
@@ -134,6 +136,9 @@ class FtpFs(AbstractedFS):
134
136
  self.listdirinfo = self.listdir
135
137
  self.chdir(".")
136
138
 
139
+ def log(self, msg , c = 0) :
140
+ self.hub.log("ftpd", msg, c)
141
+
137
142
  def v2a(
138
143
  self,
139
144
  vpath ,
@@ -202,17 +207,37 @@ class FtpFs(AbstractedFS):
202
207
  w = "w" in mode or "a" in mode or "+" in mode
203
208
 
204
209
  ap = self.rv2a(filename, r, w)[0]
210
+ self.validpath(ap)
205
211
  if w:
206
212
  try:
207
213
  st = bos.stat(ap)
208
214
  td = time.time() - st.st_mtime
215
+ need_unlink = True
209
216
  except:
217
+ need_unlink = False
210
218
  td = 0
211
219
 
212
- if td < -1 or td > self.args.ftp_wt:
213
- raise FSE("Cannot open existing file for writing")
220
+ if w and need_unlink:
221
+ if td >= -1 and td <= self.args.ftp_wt:
222
+ # within permitted timeframe; unlink and accept
223
+ do_it = True
224
+ elif self.args.no_del or self.args.ftp_no_ow:
225
+ # file too old, or overwrite not allowed; reject
226
+ do_it = False
227
+ else:
228
+ # allow overwrite if user has delete permission
229
+ # (avoids win2000 freaking out and deleting the server copy without uploading its own)
230
+ try:
231
+ self.rv2a(filename, False, True, False, True)
232
+ do_it = True
233
+ except:
234
+ do_it = False
235
+
236
+ if not do_it:
237
+ raise FSE("File already exists")
238
+
239
+ wunlink(self.log, ap, VF_CAREFUL)
214
240
 
215
- self.validpath(ap)
216
241
  return open(fsenc(ap), mode, self.args.iobuf)
217
242
 
218
243
  def chdir(self, path ) :
@@ -277,9 +302,20 @@ class FtpFs(AbstractedFS):
277
302
  # display write-only folders as empty
278
303
  return []
279
304
 
280
- # return list of volumes
281
- r = {x.split("/")[0]: 1 for x in self.hub.asrv.vfs.all_vols.keys()}
282
- return list(sorted(list(r.keys())))
305
+ # return list of accessible volumes
306
+ ret = []
307
+ for vn in self.hub.asrv.vfs.all_vols.values():
308
+ if "/" in vn.vpath or not vn.vpath:
309
+ continue # only include toplevel-mounted vols
310
+
311
+ try:
312
+ self.hub.asrv.vfs.get(vn.vpath, self.uname, True, False)
313
+ ret.append(vn.vpath)
314
+ except:
315
+ pass
316
+
317
+ ret.sort()
318
+ return ret
283
319
 
284
320
  def rmdir(self, path ) :
285
321
  ap = self.rv2a(path, d=True)[0]
@@ -429,9 +465,10 @@ class FtpHandler(FTPHandler):
429
465
  None,
430
466
  xbu,
431
467
  ap,
432
- vfs.canonical(rem),
468
+ vp,
433
469
  "",
434
470
  self.uname,
471
+ self.hub.asrv.vfs.get_perms(vp, self.uname),
435
472
  0,
436
473
  0,
437
474
  self.cli_ip,