Commit Graph

45 Commits

Author SHA1 Message Date
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 "", line 6, in <module>
    File "\...\", line 79, in send2trash
      paths = [get_short_path_name(path) for path in paths]
    File "\...\", line 79, in <listcomp>
      paths = [get_short_path_name(path) for path in paths]
    File "\...\", 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
Also prevent potential identical warning in ``.
2020-12-01 08:45:46 +01:00
Magnus Møller Jørgensen 20bbab0b4c
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 (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.

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:\
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
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.
branch : py3k
2010-10-17 18:00:56 +01:00
Virgil Dupras a6907d57a9 Converted the compiled osx module to ctypes.
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.
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.
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
Virgil Dupras 2858b5b153 Converted to py3k (haven't tried it on Windows yet, but it should compile and work...)
branch : py3k
2010-07-07 16:12:13 +02:00
Virgil Dupras f5f9c5b352 Fixed the copyright comment which was at a strange place. 2010-04-21 10:30:51 +02:00
Virgil Dupras 203973d66c Licensed under BSD. 2010-04-07 08:52:24 +02:00
Virgil Dupras ae126c47bf In plat_other, added support for sending to trash on external volumes. 2010-04-06 19:54:10 +02:00
Virgil Dupras cc15b628a2 plat_other tries to see if an Ubuntu-style trash exists and uses it. 2010-04-06 19:11:37 +02:00
Virgil Dupras 6856e49f2d Added the plat_other module (for Linux). 2010-04-06 18:55:30 +02:00
Virgil Dupras 8a1dff2947 Renamed _trash_* modules to _send2trash_* and added python wrapper around them.
rename : modules/trash_osx.c => modules/send2trash_osx.c
rename : modules/trash_win.c => modules/send2trash_win.c
2010-04-06 18:04:32 +02:00
Virgil Dupras 5aa4811725 Added the osx module. 2010-04-06 08:58:56 +02:00