Commit Graph

58 Commits

Author SHA1 Message Date
Andrew Senetar c7a23884a9
chore: Upgrade version to 1.8.3, bump CI
- Upgrade version to 1.8.3, add changelog entry
- Fix minor flake8 error that can be ignored
- Update CI workflow to use newer actions and python versions
2024-04-06 16:36:23 -07:00
Yogesh Agarwala baeb9e59f9
Fix bug in send2trash: Use os.fsdecode() in shutil.move()
`shutil.move()` function expects string paths, not byte paths. This bug is leading to failure when src and dst are on on the different file system.
2024-03-23 05:37:21 +05:30
Andrey Efremov ed039dc892 Support for any iterable type as input data 2024-01-11 14:25:22 +07:00
Mickaël Schoentgen 0a36688a4b
win/legacy: tiny logic simplification 2023-04-02 17:08:25 +02:00
Andrew Senetar 4b9bc4bc31
fix(win): Prevent exception on empty list
Add check for when an empty list remains after preprocessing and do
not continue for both legacy and modern windows implementations.

Fix #71
2022-07-26 22:42:30 -05:00
Andrew Senetar 448224954b
Replace relative imports with absolute 2022-06-01 00:22:46 -05:00
Andrew Senetar d37197c4f7
Move mac/win to subpackages & fix #64
- Move macOS and Windows implementations to sub packagese to improve organization
- Fix #64 in legacy windows implementation by mapping results to standard error codes
2022-04-30 19:52:09 -05:00
Andrew Senetar 18e51c0b5a
Minor cleanup in plat_other
- Add OSError code values
- Use INFO_SUFFIX constant in tests
- Remove old PathLike conversions
2021-08-24 01:00:02 -05:00
Andrew Senetar 78a536abba
Minor code quality updates 2021-08-21 15:19:32 -05:00
Andrew Senetar 5e4517aa53
Add fallback to HOMETRASH on plat_other
In the case where os.path.ismount() does not detect a mount and os.rename errors
fallback to HOMETRASH.  This covers several situations where continuing with
the identified trash location is incorrect due to complex mounts.

Close #26, #41, #63.
2021-08-20 22:30:51 -05:00
Andrew Senetar d0e4890a4d
Black format updates with correct line length 2021-08-17 18:58:11 -05:00
Andrew Senetar d249f0106b
Fix #59, initialize and uninitialize COM for threading 2021-08-07 22:16:33 -05:00
Andrew Senetar 94e1ec007a
Add ability to handle pathlib paths
- Handle pathlib paths across all implementations, plat_other already did
- Move preprocessing code to common location
2021-08-07 21:48:10 -05:00
Mickaël Schoentgen 436686bf0f Windows legacy: fix handling of UNC names
The legacy implementation was not handling UNC names properly:

  Traceback (most recent call last):
    File "check.py", line 6, in <module>
      send2trash(str(file))
    File "\...\plat_win_legacy.py", line 79, in send2trash
      paths = [get_short_path_name(path) for path in paths]
    File "\...\plat_win_legacy.py", line 79, in <listcomp>
      paths = [get_short_path_name(path) for path in paths]
    File "\...\plat_win_legacy.py", line 62, in get_short_path_name
      raise WindowsError(err_no, FormatError(err_no), long_name[4:])
  OSError: [Errno 123] La syntaxe du nom de fichier, de répertoire ou de volume est incorrecte.: '\\\\SERVER\\folder\\file.txt'
2021-05-26 17:22:26 +02:00
Andrew Senetar 9b0d5796c1
Change conditional for macos pyobjc usage
macOS 11.x will occasionally identify as 10.16, since there was no real
reason to prevent on all supported platforms allow.
2021-05-14 21:40:16 -05:00
Andrew Senetar 530e9b4bc6
Add initial pyobjc version for macOS
This is to help with issue #51.  Will not help in the case of python 2 or
older python 3 version < 3.6.
2021-04-13 22:36:10 -05:00
Andrew Senetar f9fcdb8d8c
Fix legacy windows platform for multibyte unicode
- Add handling to create correctly sized buffer even with multibyte
characters as len() in python does not line up with what
create_unicode_buffer() needs for length.
- Add test for single and multiple files
2021-03-10 21:41:30 -06:00
Andrew Senetar a324923ffa
Add IFileOperationProgressSink
- Add sink to allow detection of times when the file would be deleted
- Currently can detect, but not stop operations, more work needed
2021-03-02 19:23:43 -06:00
Andrew Senetar 33ed07811b
Cleanup flake8 issues 2021-03-01 23:44:03 -06:00
Andrew Senetar f64c69f905
Merge branch 'master' into master 2021-01-21 18:57:39 -06:00
Mickaël Schoentgen cd8d9fb95e Fix ResourceWarning: unclosed file in setup.py
Also prevent potential identical warning in `plat_other.py`.
2020-12-01 08:45:46 +01:00
Magnus Møller Jørgensen 20bbab0b4c
Update plat_other.py
The trash info file needs to exist before the file is moved into the trash folder. 
This is to conform to the events based detection of trashed files in gnome and other file managers.
2020-07-23 03:57:15 +02:00
Andrew Senetar 2e9fa38f56
Fix some flake8 errors and cleanup
- Fix some flake8 formatting errors
- Auto-format files edited
- Also ignore some flake8 errors when they are intented
- Update .gitignore to ingore local env
2020-06-18 21:47:06 -05:00
Andrew Senetar d078554052
Windows Performance Improvement & Multi-Item support (#43)
* Initial IFileOperation for Windows

- Try using IFileOperation instead of SHFileOperation
  - Use pywin32 to accomplish this
  - Implement fallback when pywin32 not available
- Handles paths like `C:\` just fine bu the `\\?\` paths in the test
  cause issue
- Add batching for IFileOperation version (performance)
- Minor formatting applied by editor

* Fix issue with paths starting with \\?\

- Strip these characters off if present just like old implementation

* Add windows version check, legacy list support

- Add check for windows version for IFileOperation
- Add list support to legacy version
- Remove some debugging code
- Fix bug in path converson

Not sure if there is a better way to layout this file

* Split plat_win into legacy and modern

* Update other platforms for list support

Formatter also ran on these so some other minor changes.

* Add unit tests for multi-file calls
2020-06-03 12:49:41 -04:00
Matthew D. Scholefield 9ede898c3e
Create __main__.py (Fixes #15) (#38)
This adds a main method that mimics the behavior of `rm`. It can be called via `python -m send2trash somefile`.
2020-05-27 07:52:00 -04:00
sharkykh 66afce7252 Fix silently failing on Windows (#33)
* Fix #31: Silently failing on Windows

* Update Windows test

* Fix test folders not getting removed
2019-04-30 12:28:09 -04:00
Thomas Kluyver 1dded4f572 Raise TrashPermissionError from gio backend (#22) 2018-02-16 09:30:26 -05:00
Mickaël Schoentgen 020d05979d Windows: Workaround for long paths (#23)
By using the short path version of a file, we can
manage to move long paths to the trash.

Limitations:
1/ If the final short path is longer than what
    `SHFileOperationW` can handle, it will fail
2/ Still not able to trash long path from another
    drive, ie: trying to delete C:\temp\foo.txt
    while the script is running from D:\trash.py
2018-02-16 09:07:05 -05:00
Thomas Kluyver 6b0bd46036 Define TrashPermissionError (#21) 2018-02-06 17:28:47 -05:00
Andrew Senetar 5733670fc2 Workaround embedded null character (#18)
Workaround embedded null characters in strings.  This fixes 17.
2017-11-01 08:28:22 -04:00
Virgil Dupras 3071684f73 Fix newly-introduced crash under Windows
ref #14
2017-08-07 22:51:37 -04:00
Virgil Dupras 016b90c1ac Update copyright 2017-08-03 20:52:19 -04:00
Virgil Dupras f324ff491e Properly reuse the "compat" unit 2017-08-03 20:47:58 -04:00
Thomas Kluyver 7fece243d8 Use bytes throughout plat_other 2017-08-01 12:26:09 +01:00
Kfir Hadas f6f63b1796 Use text_type (unicode for PY2, str for PY3) (#12) 2017-07-07 16:09:16 -04:00
Julian David Rath 6c01453fd3 throwing a WindowsError with the code 2016-04-12 08:53:04 +02:00
Elan Ruusamäe 72bc94b48d Update plat_other.py
minor typo fix
2016-04-10 11:09:46 +03:00
Virgil Dupras baf125ff61 Added support for Gnome's gio
Instead of using our own Freedesktop's trash implementation,
use gio when it's available.
2013-07-19 19:16:11 -04:00
Virgil Dupras bb8ed834da Add same-codebase support for python 2.7.
When I opted for two codebases for python2/python3,
Send2Trash used C modules and it was easier to just have two
packages. With the ctypes version, supporting both python
versions becomes trivial and it's much more convenient to
merge them back into a single codebase.

I've only tested this code on Linux. I've converted plat_osx and
plat_win, but they only work theoretically.
2013-07-19 18:42:32 -04:00
gbn aee2b7a8af Check access and devices before attempting trash. 2011-03-13 14:40:52 -04:00
gbn d090156c45 Use realpath to find mountpoint 2011-03-13 14:38:03 -04:00
Virgil Dupras 358b705cbc Made a few minor style fixes, and added a proper error in cases where the target path of send2trash() doesn't exist. 2011-03-12 11:48:19 +01:00
gbn eedbe258cb URL Escape the Path in trashinfo 2011-03-10 14:56:19 -05:00
gbn 18e3187c2f Replace == None with is None 2011-03-10 12:22:21 -05:00
gbn 8001be8f37 Remove import * 2011-03-10 12:21:05 -05:00
gbn 13b3943c82 Replace plat_other with one supporting the XDG Trash spec
Added tests for plat_other
2011-03-10 04:55:46 -05:00
Virgil Dupras 899a3efeb3 Converted the compiled win module to ctypes.
--HG--
branch : py3k
2010-10-17 18:00:56 +01:00
Virgil Dupras a6907d57a9 Converted the compiled osx module to ctypes.
--HG--
branch : py3k
2010-10-17 18:28:28 +02:00
Virgil Dupras 02dc392c45 Fixed a bug in plat_other where conflict handling wouldn't be done correctly in external volume. Thanks to John Benediktsson for the tip.
--HG--
branch : py3k
extra : transplant_source : %C6%11%009sx%B29%CF%EC%CC%D4%88r%BE%D8%BB%9AIa
2010-07-09 21:49:46 -07:00
Virgil Dupras 7546aa606a Fixed an infinite loop in plat_other when using a relative path in a mounted directory.
--HG--
branch : py3k
extra : transplant_source : %B4%A2%DB%EFn%BB%3A%F6%AE%06%F3%29%DB%06%FBE%D0%A2%BEt
2010-07-09 21:46:19 -07:00