mirror of
https://github.com/arsenetar/send2trash.git
synced 2025-08-30 20:49:43 +00:00
Compare commits
No commits in common. "2a88b821040383607a4e58c21327ad7cfc8ac9c4" and "7686647389d394aa8affa0c04a2741225d3b65f5" have entirely different histories.
2a88b82104
...
7686647389
@ -182,23 +182,26 @@ def send2trash(paths):
|
||||
path_b = fsencode(path)
|
||||
elif isinstance(path, bytes):
|
||||
path_b = path
|
||||
elif hasattr(path, "__fspath__"):
|
||||
# Python 3.6 PathLike protocol
|
||||
return send2trash(path.__fspath__())
|
||||
else:
|
||||
raise TypeError("str, bytes or PathLike expected, not %r" % type(path))
|
||||
|
||||
if not op.exists(path_b):
|
||||
raise OSError(errno.ENOENT, "File not found: %s" % path)
|
||||
raise OSError("File not found: %s" % path)
|
||||
# ...should check whether the user has the necessary permissions to delete
|
||||
# it, before starting the trashing operation itself. [2]
|
||||
if not os.access(path_b, os.W_OK):
|
||||
raise OSError(errno.EACCES, "Permission denied: %s" % path)
|
||||
|
||||
raise OSError("Permission denied: %s" % path)
|
||||
# if the file to be trashed is on the same device as HOMETRASH we
|
||||
# want to move it there.
|
||||
path_dev = get_dev(path_b)
|
||||
|
||||
# If XDG_DATA_HOME or HOMETRASH do not yet exist we need to stat the
|
||||
# home directory, and these paths will be created further on if needed.
|
||||
trash_dev = get_dev(op.expanduser(b"~"))
|
||||
|
||||
# if the file to be trashed is on the same device as HOMETRASH we
|
||||
# want to move it there.
|
||||
if path_dev == trash_dev:
|
||||
topdir = XDG_DATA_HOME
|
||||
dest_trash = HOMETRASH_B
|
||||
|
@ -22,7 +22,6 @@ if sys.platform != "win32":
|
||||
import send2trash.plat_other
|
||||
from send2trash.plat_other import send2trash as s2t
|
||||
|
||||
INFO_SUFFIX = send2trash.plat_other.INFO_SUFFIX.decode()
|
||||
HOMETRASH = send2trash.plat_other.HOMETRASH
|
||||
else:
|
||||
pytest.skip("Skipping non-windows tests", allow_module_level=True)
|
||||
@ -40,7 +39,7 @@ def testfile():
|
||||
# Remove trash files if they exist
|
||||
if op.exists(op.join(HOMETRASH, "files", name)):
|
||||
os.remove(op.join(HOMETRASH, "files", name))
|
||||
os.remove(op.join(HOMETRASH, "info", name + INFO_SUFFIX))
|
||||
os.remove(op.join(HOMETRASH, "info", name + ".trashinfo"))
|
||||
if op.exists(file.name):
|
||||
os.remove(file.name)
|
||||
|
||||
@ -60,7 +59,7 @@ def testfiles():
|
||||
yield files
|
||||
filenames = [op.basename(file.name) for file in files]
|
||||
[os.remove(op.join(HOMETRASH, "files", filename)) for filename in filenames]
|
||||
[os.remove(op.join(HOMETRASH, "info", filename + INFO_SUFFIX)) for filename in filenames]
|
||||
[os.remove(op.join(HOMETRASH, "info", filename + ".trashinfo")) for filename in filenames]
|
||||
|
||||
|
||||
def test_trash(testfile):
|
||||
@ -95,7 +94,7 @@ def gen_unicode_file():
|
||||
# Cleanup trash files on supported platforms
|
||||
if sys.platform != "win32" and op.exists(op.join(HOMETRASH, "files", name)):
|
||||
os.remove(op.join(HOMETRASH, "files", name))
|
||||
os.remove(op.join(HOMETRASH, "info", name + INFO_SUFFIX))
|
||||
os.remove(op.join(HOMETRASH, "info", name + ".trashinfo"))
|
||||
if op.exists(file):
|
||||
os.remove(file)
|
||||
|
||||
@ -163,11 +162,11 @@ def test_trash_topdir(gen_ext_vol):
|
||||
s2t(gen_ext_vol[2])
|
||||
assert op.exists(gen_ext_vol[2]) is False
|
||||
assert op.exists(op.join(trash_dir, str(os.getuid()), "files", gen_ext_vol[1])) is True
|
||||
assert op.exists(op.join(trash_dir, str(os.getuid()), "info", gen_ext_vol[1] + INFO_SUFFIX,)) is True
|
||||
assert op.exists(op.join(trash_dir, str(os.getuid()), "info", gen_ext_vol[1] + ".trashinfo",)) is True
|
||||
# info relative path (if another test is added, with the same fileName/Path,
|
||||
# then it gets renamed etc.)
|
||||
cfg = ConfigParser()
|
||||
cfg.read(op.join(trash_dir, str(os.getuid()), "info", gen_ext_vol[1] + INFO_SUFFIX))
|
||||
cfg.read(op.join(trash_dir, str(os.getuid()), "info", gen_ext_vol[1] + ".trashinfo"))
|
||||
assert (gen_ext_vol[1] == cfg.get("Trash Info", "Path", raw=True)) is True
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user