aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVG <vg@devys.org>2016-12-09 11:52:12 +0100
committerVG <vg@devys.org>2016-12-09 11:52:12 +0100
commitf942001c3eea6fedb838ebf22720ab507c77e192 (patch)
tree7130d40b548d337a8d2c86e7a24d1f275fe9dde7
parent55dbce5e34e8d1c4047f6c8369cb05715495a296 (diff)
downloadclip-f942001c3eea6fedb838ebf22720ab507c77e192.tar.gz
clip-f942001c3eea6fedb838ebf22720ab507c77e192.tar.bz2
clip-f942001c3eea6fedb838ebf22720ab507c77e192.zip
use write to be able to create the file when non-existant
-rwxr-xr-xclip10
1 files changed, 2 insertions, 8 deletions
diff --git a/clip b/clip
index 6e480b4..29e73e3 100755
--- a/clip
+++ b/clip
@@ -37,18 +37,12 @@ def fileno(filelike):
@contextlib.contextmanager
-def secure_open(path, mode='r', *l, **kw):
+def secure_open(path, *l, **kw):
if os.path.islink(path):
raise SecurityError("The clipboard file can not be a symlink")
- real_mode = mode
- if 'w' in real_mode:
- real_mode = real_mode.replace('w', 'a')
- with open(path, real_mode, *l, **kw) as fo:
+ with open(path, *l, **kw) as fo:
if os.fstat(fileno(fo)) != os.stat(path):
raise SecurityError("Intrusion might have been done on %s" % path)
- if 'w' in mode:
- os.lseek(fileno(fo), 0, os.SEEK_SET)
- os.ftruncate(fileno(fo), 0)
os.fchmod(fileno(fo), 0o600)
yield fo