python - Lock directory when uploading to it -


i've been thinking of updating directory name username , datetime when user uploads files it. newest upload user show on it. have upload function , rename so:

# check if form valid , upload        if form.is_valid():         form.save(request.files, request)     # edit previous folder have new datetime , user marking if folder has such.     currentpath = post_data.get('path').encode("utf-8")     prevfolder = os.path.basename(post_data.get('path').encode("utf-8"))     try:         casename, rest = prevfolder.split(" [",1)     #print(casename)         dest = renameonupload(request,currentpath, casename)     except:         dest = form.path          return httpresponseredirect('/fm/list/%s' % dest)  def renameonupload(request,path,casename):     datetime_string = get_currenttime()     user_string = " ["+ request.user.username + "]"     newcasename = casename+user_string.encode("utf-8")+datetime_string     dest = os.path.join(os.path.dirname(path), newcasename)     if not path == dest:         fmoper.move(path, dest)     else:         dest = path     return dest 

fmoper.move

def move(src, dst, replace=false):     ensure_dir(dst)             # ensure have destination folder, if not create it.      if not replace , os.path.exists(dst):         dst = existname(dst)     return shutil.move(src, dst) 

so uploads files , move after. causes problems when user uploading , 1 uploads @ same time, renaming folder in process causing 1 uploader upload folder doesn't exist.

is there neat way lock folder when user uploading it? currentpath folder uploaded , dest renamed one.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -