summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2021-12-30 20:03:34 +0000
committerPhilip Sargent <philip.sargent@klebos.com>2021-12-30 20:03:34 +0000
commitc3a54858d5bd253186eb3d318a58a240137f8a10 (patch)
tree96e817b1f2287e5a7da91e9f5aaea9f4b4cab7f6
parent0a3037f077dabc39c386a6aea5668b661e64ea7b (diff)
downloadtroggle-c3a54858d5bd253186eb3d318a58a240137f8a10.tar.gz
troggle-c3a54858d5bd253186eb3d318a58a240137f8a10.tar.bz2
troggle-c3a54858d5bd253186eb3d318a58a240137f8a10.zip
chmod with context handler
-rw-r--r--core/models/caves.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/core/models/caves.py b/core/models/caves.py
index 313935a..4ecbfdb 100644
--- a/core/models/caves.py
+++ b/core/models/caves.py
@@ -40,7 +40,7 @@ todo='''- Move utility function into utils.py
def writetrogglefile(filepath, filecontent):
'''Set permissions to rw-rw-r-- and commit the new saved file to git
- Callers should handle exception PermissionsError explicitly
+ Callers to cave.writeDataFile() or entrance.writeDataFile() should handle the exception PermissionsError explicitly
'''
filepath = Path(filepath)
cwd = filepath.parent
@@ -48,8 +48,10 @@ def writetrogglefile(filepath, filecontent):
git = settings.GIT
# do not trap exceptions, pass them up to the view that called this function
+ # if the os.chmod fails, it can zero the contents of the file as a side effect. Dangerous.
with open(filepath, "w") as f:
- os.chmod(filepath, 0o664) # set file permissions to rw-rw-r--
+ f.chmod(0o664) # safely set file permissions to rw-rw-r--
+ # os.chmod(filepath, 0o664) # set file permissions to rw-rw-r--
f.write(filecontent)
print(f'WRITING{cwd}---{filename} ')
call([git, "add", filename], cwd=cwd)