forked from pymedusa/Medusa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix sending to trash not working on Python 3.6+ (pymedusa#6625)
* send2trash v1.5.0 * Apply fix * Update changelog
- Loading branch information
Showing
9 changed files
with
155 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
# Copyright 2013 Hardcoded Software (http://www.hardcoded.net) | ||
# Copyright 2017 Virgil Dupras | ||
|
||
# This software is licensed under the "BSD" License as described in the "LICENSE" file, | ||
# which should be included with this package. The terms are also available at | ||
# This software is licensed under the "BSD" License as described in the "LICENSE" file, | ||
# which should be included with this package. The terms are also available at | ||
# http://www.hardcoded.net/licenses/bsd_license | ||
|
||
import sys | ||
if sys.version < '3': | ||
text_type = unicode | ||
binary_type = str | ||
else: | ||
import os | ||
|
||
PY3 = sys.version_info[0] >= 3 | ||
if PY3: | ||
text_type = str | ||
binary_type = bytes | ||
if os.supports_bytes_environ: | ||
# environb will be unset under Windows, but then again we're not supposed to use it. | ||
environb = os.environb | ||
else: | ||
text_type = unicode | ||
binary_type = str | ||
environb = os.environ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import errno | ||
from .compat import PY3 | ||
|
||
if PY3: | ||
_permission_error = PermissionError | ||
else: | ||
_permission_error = OSError | ||
|
||
class TrashPermissionError(_permission_error): | ||
"""A permission error specific to a trash directory. | ||
Raising this error indicates that permissions prevent us efficiently | ||
trashing a file, although we might still have permission to delete it. | ||
This is *not* used when permissions prevent removing the file itself: | ||
that will be raised as a regular PermissionError (OSError on Python 2). | ||
Application code that catches this may try to simply delete the file, | ||
or prompt the user to decide, or (on Freedesktop platforms), move it to | ||
'home trash' as a fallback. This last option probably involves copying the | ||
data between partitions, devices, or network drives, so we don't do it as | ||
a fallback. | ||
""" | ||
def __init__(self, filename): | ||
_permission_error.__init__(self, errno.EACCES, "Permission denied", | ||
filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
# Copyright 2013 Hardcoded Software (http://www.hardcoded.net) | ||
# Copyright 2017 Virgil Dupras | ||
|
||
# This software is licensed under the "BSD" License as described in the "LICENSE" file, | ||
# which should be included with this package. The terms are also available at | ||
# This software is licensed under the "BSD" License as described in the "LICENSE" file, | ||
# which should be included with this package. The terms are also available at | ||
# http://www.hardcoded.net/licenses/bsd_license | ||
|
||
from gi.repository import GObject, Gio | ||
from .exceptions import TrashPermissionError | ||
|
||
def send2trash(path): | ||
try: | ||
f = Gio.File.new_for_path(path) | ||
f.trash(cancellable=None) | ||
except GObject.GError as e: | ||
if e.code == Gio.IOErrorEnum.NOT_SUPPORTED: | ||
# We get here if we can't create a trash directory on the same | ||
# device. I don't know if other errors can result in NOT_SUPPORTED. | ||
raise TrashPermissionError('') | ||
raise OSError(e.message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters