Don't make the user's files read-only.

Copy the data to a temporary file before marking it read-only.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
brian m. carlson 2014-01-11 00:36:30 +00:00
parent c3d30291ec
commit 44b9c5c031
No known key found for this signature in database
GPG key ID: BF535D811F52F68B

15
newfol
View file

@ -13,6 +13,7 @@ import locale
import os
import os.path
import re
import shutil
import subprocess
import tempfile
import urwid
@ -899,6 +900,17 @@ class MenuView(ListView):
self.OPTIONS.keys()])
return self._render_listview("Main Menu", self.OPTIONS.keys(), content)
def display_read_only(name):
"""Display this file read-only.
Try very hard to ensure the user does not modify it.
"""
tempdir = tempfile.TemporaryDirectory()
temp = os.path.join(tempdir.name, "view")
shutil.copyfile(name, temp)
os.chmod(temp, 0o400)
subprocess.call(["sensible-editor", temp])
def display_cheat_sheet(name, loop):
if name is None:
mbox = MessageBox("No cheat sheet was registered in the schema file.")
@ -908,8 +920,7 @@ def display_cheat_sheet(name, loop):
mbox = MessageBox("The cheat sheet file doesn't exist.")
mbox.render(loop)
return
os.chmod(name, 0o400)
subprocess.call(["sensible-editor", name])
display_read_only(name)
def render_previous_view(loop):
if len(DatabaseData().views) > 1: