From af5f84919e804999e840dba4b0131338528491fd Mon Sep 17 00:00:00 2001 From: j Date: Thu, 14 Jan 2016 12:29:55 +0530 Subject: [PATCH] make files read only --- oml/item/models.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/oml/item/models.py b/oml/item/models.py index c6e6478..268b354 100644 --- a/oml/item/models.py +++ b/oml/item/models.py @@ -7,6 +7,7 @@ import hashlib import os import re import shutil +import stat import unicodedata from PIL import Image @@ -550,6 +551,14 @@ class File(db.Model): prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/') return os.path.join(prefix, self.path) + def make_readonly(self): + 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 + if mode != readonly: + os.chmod(current_path, readonly) + def move(self): def format_underscores(string): return re.sub('^\.|\.$|:|/|\?|<|>', '_', string) @@ -561,6 +570,9 @@ class File(db.Model): if not os.path.exists(current_path): logger.debug('file is missing. %s', current_path) return + + self.make_readonly() + author = '; '.join([get_sort_name(a) for a in j.get('author', [])]) if not author: author = 'Unknown Author'