fix permissions

This commit is contained in:
j 2017-05-30 21:02:58 +02:00
parent 3ecd742bd8
commit 56477d2757
1 changed files with 5 additions and 3 deletions

View File

@ -578,8 +578,9 @@ class Item(db.Model):
for f in self.files.all():
path = f.fullpath()
if os.path.exists(path):
mode = 0o644
try:
os.chmod(path, stat.S_IWRITE)
os.chmod(path, mode)
os.unlink(path)
remove_empty_folders(os.path.dirname(path))
except:
@ -725,7 +726,7 @@ class File(db.Model):
current_path = self.fullpath()
if os.path.exists(current_path):
mode = os.stat(current_path)[stat.ST_MODE]
readonly = mode & ~stat.S_IWUSR & ~stat.S_IWGRP & ~stat.S_IWOTH
readonly = 0o444
if mode != readonly:
os.chmod(current_path, readonly)
@ -787,8 +788,9 @@ class File(db.Model):
if self.path != new_path:
path = os.path.join(prefix, new_path)
ox.makedirs(os.path.dirname(path))
mode = 0o644
try:
os.chmod(current_path, stat.S_IWRITE)
os.chmod(current_path, mode)
shutil.move(current_path, path)
except:
logger.debug('failed to move %s to %s', current_path, path, exc_info=True)