26 except ImportError: |
27 except ImportError: |
27 # Python 2 |
28 # Python 2 |
28 from urllib import quote |
29 from urllib import quote |
29 |
30 |
30 from .compat import text_type, environb |
31 from .compat import text_type, environb |
|
32 from .exceptions import TrashPermissionError |
31 |
33 |
32 try: |
34 try: |
33 fsencode = os.fsencode # Python 3 |
35 fsencode = os.fsencode # Python 3 |
34 fsdecode = os.fsdecode |
36 fsdecode = os.fsdecode |
35 except AttributeError: |
37 except AttributeError: |
132 return trash_dir |
134 return trash_dir |
133 |
135 |
134 def find_ext_volume_fallback_trash(volume_root): |
136 def find_ext_volume_fallback_trash(volume_root): |
135 # from [2] Trash directories (1) create a .Trash-$uid dir. |
137 # from [2] Trash directories (1) create a .Trash-$uid dir. |
136 trash_dir = op.join(volume_root, TOPDIR_FALLBACK) |
138 trash_dir = op.join(volume_root, TOPDIR_FALLBACK) |
137 # Try to make the directory, if we can't the OSError exception will escape |
139 # Try to make the directory, if we lack permission, raise TrashPermissionError |
138 # be thrown out of send2trash. |
140 try: |
139 check_create(trash_dir) |
141 check_create(trash_dir) |
|
142 except OSError as e: |
|
143 if e.errno == errno.EACCES: |
|
144 raise TrashPermissionError(e.filename) |
|
145 raise |
140 return trash_dir |
146 return trash_dir |
141 |
147 |
142 def find_ext_volume_trash(volume_root): |
148 def find_ext_volume_trash(volume_root): |
143 trash_dir = find_ext_volume_global_trash(volume_root) |
149 trash_dir = find_ext_volume_global_trash(volume_root) |
144 if trash_dir is None: |
150 if trash_dir is None: |