fix permissions

This commit is contained in:
j 2017-05-30 21:02:58 +02:00
parent 3ecd742bd8
commit 56477d2757

View file

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