/usr/share/pyshared/integration_tests/files.py is in trash-cli 0.12.7-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | # Copyright (C) 2011 Andrea Francia Trivolzio(PV) Italy
from nose.tools import assert_equals
from trashcli.trash import has_sticky_bit
import os, shutil
def having_file(path):
dirname=os.path.dirname(path)
if dirname != '': make_dirs(dirname)
open(path,'w').close()
assert os.path.isfile(path)
make_empty_file = having_file
def write_file(filename, contents=''):
parent = os.path.dirname(filename)
if not os.path.isdir(parent): os.makedirs(parent)
file(filename, 'w').write(contents)
assert_equals(file(filename).read(), contents)
def require_empty_dir(path):
if os.path.exists(path): shutil.rmtree(path)
make_dirs(path)
def having_empty_dir(path):
require_empty_dir(path)
def make_dirs(path):
if not os.path.isdir(path):
os.makedirs(path)
assert os.path.isdir(path)
def make_parent_for(path):
parent = os.path.dirname(path)
make_dirs(parent)
def make_sticky_dir(path):
os.mkdir(path)
set_sticky_bit(path)
def make_unsticky_dir(path):
os.mkdir(path)
unset_sticky_bit(path)
def make_dir_unsticky(path):
assert_is_dir(path)
unset_sticky_bit(path)
def assert_is_dir(path):
assert os.path.isdir(path)
def set_sticky_bit(path):
import stat
os.chmod(path, os.stat(path).st_mode | stat.S_ISVTX)
def unset_sticky_bit(path):
import stat
os.chmod(path, os.stat(path).st_mode & ~ stat.S_ISVTX)
assert not has_sticky_bit(path)
def touch(path):
open(path,'a+').close()
def ensure_non_sticky_dir(path):
import os
assert os.path.isdir(path)
assert not has_sticky_bit(path)
def make_unreadable_file(path):
write_file(path, '')
import os
os.chmod(path, 0)
from nose.tools import assert_raises
with assert_raises(IOError):
file(path).read()
|