Hello community, here is the log from the commit of package python-Send2Trash for openSUSE:Factory checked in at 2019-03-22 15:00:18 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-Send2Trash (Old) and /work/SRC/openSUSE:Factory/.python-Send2Trash.new.25356 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-Send2Trash" Fri Mar 22 15:00:18 2019 rev:3 rq:682096 version:1.5.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-Send2Trash/python-Send2Trash.changes 2018-12-19 13:54:08.790892373 +0100 +++ /work/SRC/openSUSE:Factory/.python-Send2Trash.new.25356/python-Send2Trash.changes 2019-03-22 15:00:22.197827737 +0100 @@ -1,0 +2,9 @@ +Wed Mar 6 10:34:17 UTC 2019 - Tomáš Chvátal <tchva...@suse.com> + +- Update to 1.5.0: + * More specific error when failing to create XDG fallback trash directory (#20) + * Windows: Workaround for long paths (#23) +- Add patch to test properly under python2: + * python2.patch + +------------------------------------------------------------------- Old: ---- Send2Trash-1.4.1.tar.gz New: ---- Send2Trash-1.5.0.tar.gz python2.patch ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-Send2Trash.spec ++++++ --- /var/tmp/diff_new_pack.2xZlND/_old 2019-03-22 15:00:22.965827217 +0100 +++ /var/tmp/diff_new_pack.2xZlND/_new 2019-03-22 15:00:22.969827215 +0100 @@ -1,7 +1,7 @@ # # spec file for package python-Send2Trash # -# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -18,20 +18,21 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} # test scripts missing -%bcond_with test %define oldpython python Name: python-Send2Trash -Version: 1.4.1 +Version: 1.5.0 Release: 0 Summary: Python library to send files to the Trash location License: BSD-3-Clause Group: Development/Languages/Python Url: https://github.com/hsoft/send2trash Source: https://files.pythonhosted.org/packages/source/S/Send2Trash/Send2Trash-%{version}.tar.gz +Patch0: python2.patch BuildRequires: %{python_module setuptools} BuildRequires: fdupes BuildRequires: python-rpm-macros -Recommends: python-gobject +Requires: typelib(GObject) +Requires: typelib(Gio) %ifpython2 Obsoletes: %{oldpython}-send2trash < %{version} Provides: %{oldpython}-send2trash = %{version} @@ -51,6 +52,7 @@ %prep %setup -q -n Send2Trash-%{version} +%patch0 -p1 %build %python_build @@ -59,13 +61,12 @@ %python_install %python_expand %fdupes %{buildroot}%{$python_sitelib} -%if %{with test} %check -%python_exec setup.py test -%endif +export LANG=en_US.UTF8 +%python_expand PYTHONPATH=%{buildroot}%{$python_sitelib} $python -m unittest discover %files %{python_files} -%defattr(-,root,root,-) +%license LICENSE %doc CHANGES.rst README.rst %{python_sitelib}/* ++++++ Send2Trash-1.4.1.tar.gz -> Send2Trash-1.5.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/.gitignore new/Send2Trash-1.5.0/.gitignore --- old/Send2Trash-1.4.1/.gitignore 1970-01-01 01:00:00.000000000 +0100 +++ new/Send2Trash-1.5.0/.gitignore 2017-08-04 02:31:26.000000000 +0200 @@ -0,0 +1,7 @@ +*.pyc +*.egg-info +/build +/dist +.DS_Store +/.tox +__pycache__ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/.travis.yml new/Send2Trash-1.5.0/.travis.yml --- old/Send2Trash-1.4.1/.travis.yml 1970-01-01 01:00:00.000000000 +0100 +++ new/Send2Trash-1.5.0/.travis.yml 2018-02-16 15:50:54.000000000 +0100 @@ -0,0 +1,10 @@ +language: python +python: + - "2.7" + - "3.4" + - "3.5" + - "3.6" +install: + - "pip install tox" +script: + - "tox -e $(echo py$TRAVIS_PYTHON_VERSION | tr -d .)" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/CHANGES.rst new/Send2Trash-1.5.0/CHANGES.rst --- old/Send2Trash-1.4.1/CHANGES.rst 2017-08-08 05:12:18.000000000 +0200 +++ new/Send2Trash-1.5.0/CHANGES.rst 2018-02-16 15:56:34.000000000 +0100 @@ -1,6 +1,17 @@ Changes ======= +Version 1.5.0 -- 2018/02/16 +--------------------------- + +* More specific error when failing to create XDG fallback trash directory (#20) +* Windows: Workaround for long paths (#23) + +Version 1.4.2 -- 2017/11/17 +--------------------------- + +* Fix incompatibility with Python 3.6 on Windows. (#18) + Version 1.4.1 -- 2017/08/07 --------------------------- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/LICENSE new/Send2Trash-1.5.0/LICENSE --- old/Send2Trash-1.4.1/LICENSE 1970-01-01 01:00:00.000000000 +0100 +++ new/Send2Trash-1.5.0/LICENSE 2017-08-04 02:48:45.000000000 +0200 @@ -0,0 +1,10 @@ +Copyright (c) 2017, Virgil Dupras +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * Neither the name of Hardcoded Software Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/MANIFEST.in new/Send2Trash-1.5.0/MANIFEST.in --- old/Send2Trash-1.4.1/MANIFEST.in 2017-07-31 20:11:50.000000000 +0200 +++ new/Send2Trash-1.5.0/MANIFEST.in 2018-02-16 15:40:05.000000000 +0100 @@ -1 +1 @@ -include CHANGES.rst \ No newline at end of file +include CHANGES.rst LICENSE diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/PKG-INFO new/Send2Trash-1.5.0/PKG-INFO --- old/Send2Trash-1.4.1/PKG-INFO 2017-08-08 05:13:08.000000000 +0200 +++ new/Send2Trash-1.5.0/PKG-INFO 2018-02-16 15:59:51.000000000 +0100 @@ -1,11 +1,12 @@ Metadata-Version: 1.1 Name: Send2Trash -Version: 1.4.1 +Version: 1.5.0 Summary: Send file to trash natively under Mac OS X, Windows and Linux. Home-page: https://github.com/hsoft/send2trash Author: Virgil Dupras Author-email: hs...@hardcoded.net License: BSD License +Description-Content-Type: UNKNOWN Description: ================================================== Send2Trash -- Send files to trash on all platforms ================================================== @@ -37,7 +38,15 @@ >>> from send2trash import send2trash >>> send2trash('some_file') - When there's a problem ``OSError`` is raised. + On Freedesktop platforms (Linux, BSD, etc.), you may not be able to efficiently + trash some files. In these cases, an exception ``send2trash.TrashPermissionError`` + is raised, so that the application can handle this case. This inherits from + ``PermissionError`` (``OSError`` on Python 2). Specifically, this affects + files on a different device to the user's home directory, where the root of the + device does not have a ``.Trash`` directory, and we don't have permission to + create a ``.Trash-$UID`` directory. + + For any other problem, ``OSError`` is raised. .. _PyGObject: https://wiki.gnome.org/PyGObject .. _GIO: https://developer.gnome.org/gio/ @@ -47,6 +56,17 @@ Changes ======= + Version 1.5.0 -- 2018/02/16 + --------------------------- + + * More specific error when failing to create XDG fallback trash directory (#20) + * Windows: Workaround for long paths (#23) + + Version 1.4.2 -- 2017/11/17 + --------------------------- + + * Fix incompatibility with Python 3.6 on Windows. (#18) + Version 1.4.1 -- 2017/08/07 --------------------------- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/README.rst new/Send2Trash-1.5.0/README.rst --- old/Send2Trash-1.4.1/README.rst 2017-07-31 20:11:50.000000000 +0200 +++ new/Send2Trash-1.5.0/README.rst 2018-02-16 15:40:05.000000000 +0100 @@ -29,7 +29,15 @@ >>> from send2trash import send2trash >>> send2trash('some_file') -When there's a problem ``OSError`` is raised. +On Freedesktop platforms (Linux, BSD, etc.), you may not be able to efficiently +trash some files. In these cases, an exception ``send2trash.TrashPermissionError`` +is raised, so that the application can handle this case. This inherits from +``PermissionError`` (``OSError`` on Python 2). Specifically, this affects +files on a different device to the user's home directory, where the root of the +device does not have a ``.Trash`` directory, and we don't have permission to +create a ``.Trash-$UID`` directory. + +For any other problem, ``OSError`` is raised. .. _PyGObject: https://wiki.gnome.org/PyGObject .. _GIO: https://developer.gnome.org/gio/ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/Send2Trash.egg-info/PKG-INFO new/Send2Trash-1.5.0/Send2Trash.egg-info/PKG-INFO --- old/Send2Trash-1.4.1/Send2Trash.egg-info/PKG-INFO 2017-08-08 05:13:08.000000000 +0200 +++ new/Send2Trash-1.5.0/Send2Trash.egg-info/PKG-INFO 2018-02-16 15:59:51.000000000 +0100 @@ -1,11 +1,12 @@ Metadata-Version: 1.1 Name: Send2Trash -Version: 1.4.1 +Version: 1.5.0 Summary: Send file to trash natively under Mac OS X, Windows and Linux. Home-page: https://github.com/hsoft/send2trash Author: Virgil Dupras Author-email: hs...@hardcoded.net License: BSD License +Description-Content-Type: UNKNOWN Description: ================================================== Send2Trash -- Send files to trash on all platforms ================================================== @@ -37,7 +38,15 @@ >>> from send2trash import send2trash >>> send2trash('some_file') - When there's a problem ``OSError`` is raised. + On Freedesktop platforms (Linux, BSD, etc.), you may not be able to efficiently + trash some files. In these cases, an exception ``send2trash.TrashPermissionError`` + is raised, so that the application can handle this case. This inherits from + ``PermissionError`` (``OSError`` on Python 2). Specifically, this affects + files on a different device to the user's home directory, where the root of the + device does not have a ``.Trash`` directory, and we don't have permission to + create a ``.Trash-$UID`` directory. + + For any other problem, ``OSError`` is raised. .. _PyGObject: https://wiki.gnome.org/PyGObject .. _GIO: https://developer.gnome.org/gio/ @@ -47,6 +56,17 @@ Changes ======= + Version 1.5.0 -- 2018/02/16 + --------------------------- + + * More specific error when failing to create XDG fallback trash directory (#20) + * Windows: Workaround for long paths (#23) + + Version 1.4.2 -- 2017/11/17 + --------------------------- + + * Fix incompatibility with Python 3.6 on Windows. (#18) + Version 1.4.1 -- 2017/08/07 --------------------------- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/Send2Trash.egg-info/SOURCES.txt new/Send2Trash-1.5.0/Send2Trash.egg-info/SOURCES.txt --- old/Send2Trash-1.4.1/Send2Trash.egg-info/SOURCES.txt 2017-08-08 05:13:08.000000000 +0200 +++ new/Send2Trash-1.5.0/Send2Trash.egg-info/SOURCES.txt 2018-02-16 15:59:51.000000000 +0100 @@ -1,14 +1,22 @@ +.gitignore +.travis.yml CHANGES.rst +LICENSE MANIFEST.in README.rst setup.py +tox.ini Send2Trash.egg-info/PKG-INFO Send2Trash.egg-info/SOURCES.txt Send2Trash.egg-info/dependency_links.txt Send2Trash.egg-info/top_level.txt send2trash/__init__.py send2trash/compat.py +send2trash/exceptions.py send2trash/plat_gio.py send2trash/plat_osx.py send2trash/plat_other.py -send2trash/plat_win.py \ No newline at end of file +send2trash/plat_win.py +tests/__init__.py +tests/test_plat_other.py +tests/test_plat_win.py \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/send2trash/__init__.py new/Send2Trash-1.5.0/send2trash/__init__.py --- old/Send2Trash-1.4.1/send2trash/__init__.py 2017-07-31 20:11:50.000000000 +0200 +++ new/Send2Trash-1.5.0/send2trash/__init__.py 2018-02-16 15:40:05.000000000 +0100 @@ -6,6 +6,8 @@ import sys +from .exceptions import TrashPermissionError + if sys.platform == 'darwin': from .plat_osx import send2trash elif sys.platform == 'win32': diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/send2trash/exceptions.py new/Send2Trash-1.5.0/send2trash/exceptions.py --- old/Send2Trash-1.4.1/send2trash/exceptions.py 1970-01-01 01:00:00.000000000 +0100 +++ new/Send2Trash-1.5.0/send2trash/exceptions.py 2018-02-16 15:40:05.000000000 +0100 @@ -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) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/send2trash/plat_gio.py new/Send2Trash-1.5.0/send2trash/plat_gio.py --- old/Send2Trash-1.4.1/send2trash/plat_gio.py 2017-08-04 02:51:18.000000000 +0200 +++ new/Send2Trash-1.5.0/send2trash/plat_gio.py 2018-02-16 15:40:05.000000000 +0100 @@ -5,10 +5,15 @@ # 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) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/send2trash/plat_other.py new/Send2Trash-1.5.0/send2trash/plat_other.py --- old/Send2Trash-1.4.1/send2trash/plat_other.py 2017-08-04 02:51:38.000000000 +0200 +++ new/Send2Trash-1.5.0/send2trash/plat_other.py 2018-02-16 15:40:05.000000000 +0100 @@ -16,6 +16,7 @@ from __future__ import unicode_literals +import errno import sys import os import os.path as op @@ -28,6 +29,7 @@ from urllib import quote from .compat import text_type, environb +from .exceptions import TrashPermissionError try: fsencode = os.fsencode # Python 3 @@ -134,9 +136,13 @@ def find_ext_volume_fallback_trash(volume_root): # from [2] Trash directories (1) create a .Trash-$uid dir. trash_dir = op.join(volume_root, TOPDIR_FALLBACK) - # Try to make the directory, if we can't the OSError exception will escape - # be thrown out of send2trash. - check_create(trash_dir) + # Try to make the directory, if we lack permission, raise TrashPermissionError + try: + check_create(trash_dir) + except OSError as e: + if e.errno == errno.EACCES: + raise TrashPermissionError(e.filename) + raise return trash_dir def find_ext_volume_trash(volume_root): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/send2trash/plat_win.py new/Send2Trash-1.5.0/send2trash/plat_win.py --- old/Send2Trash-1.4.1/send2trash/plat_win.py 2017-08-04 02:51:45.000000000 +0200 +++ new/Send2Trash-1.5.0/send2trash/plat_win.py 2018-02-16 15:40:05.000000000 +0100 @@ -6,15 +6,20 @@ from __future__ import unicode_literals -from ctypes import windll, Structure, byref, c_uint +from ctypes import (windll, Structure, byref, c_uint, + create_unicode_buffer, addressof) from ctypes.wintypes import HWND, UINT, LPCWSTR, BOOL import os.path as op from .compat import text_type +kernel32 = windll.kernel32 +GetShortPathNameW = kernel32.GetShortPathNameW + shell32 = windll.shell32 SHFileOperationW = shell32.SHFileOperationW + class SHFILEOPSTRUCTW(Structure): _fields_ = [ ("hwnd", HWND), @@ -27,6 +32,7 @@ ("lpszProgressTitle", LPCWSTR), ] + FO_MOVE = 1 FO_COPY = 2 FO_DELETE = 3 @@ -38,15 +44,38 @@ FOF_ALLOWUNDO = 64 FOF_NOERRORUI = 1024 + +def get_short_path_name(long_name): + if not long_name.startswith('\\\\?\\'): + long_name = '\\\\?\\' + long_name + buf_size = GetShortPathNameW(long_name, None, 0) + output = create_unicode_buffer(buf_size) + GetShortPathNameW(long_name, output, buf_size) + return output.value[4:] # Remove '\\?\' for SHFileOperationW + + def send2trash(path): if not isinstance(path, text_type): path = text_type(path, 'mbcs') if not op.isabs(path): path = op.abspath(path) + path = get_short_path_name(path) fileop = SHFILEOPSTRUCTW() fileop.hwnd = 0 fileop.wFunc = FO_DELETE - fileop.pFrom = LPCWSTR(path + '\0') + # FIX: https://github.com/hsoft/send2trash/issues/17 + # Starting in python 3.6.3 it is no longer possible to use: + # LPCWSTR(path + '\0') directly as embedded null characters are no longer + # allowed in strings + # Workaround + # - create buffer of c_wchar[] (LPCWSTR is based on this type) + # - buffer is two c_wchar characters longer (double null terminator) + # - cast the address of the buffer to a LPCWSTR + # NOTE: based on how python allocates memory for these types they should + # always be zero, if this is ever not true we can go back to explicitly + # setting the last two characters to null using buffer[index] = '\0'. + buffer = create_unicode_buffer(path, len(path)+2) + fileop.pFrom = LPCWSTR(addressof(buffer)) fileop.pTo = None fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT fileop.fAnyOperationsAborted = 0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/setup.py new/Send2Trash-1.5.0/setup.py --- old/Send2Trash-1.4.1/setup.py 2017-08-08 05:12:27.000000000 +0200 +++ new/Send2Trash-1.5.0/setup.py 2018-02-16 15:56:58.000000000 +0100 @@ -19,7 +19,7 @@ setup( name='Send2Trash', - version='1.4.1', + version='1.5.0', author='Virgil Dupras', author_email='hs...@hardcoded.net', packages=['send2trash'], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/tests/test_plat_other.py new/Send2Trash-1.5.0/tests/test_plat_other.py --- old/Send2Trash-1.4.1/tests/test_plat_other.py 1970-01-01 01:00:00.000000000 +0100 +++ new/Send2Trash-1.5.0/tests/test_plat_other.py 2017-08-04 03:02:16.000000000 +0200 @@ -0,0 +1,170 @@ +# encoding: utf-8 +import codecs +import unittest +import os +from os import path as op +import send2trash.plat_other +from send2trash.plat_other import send2trash as s2t +from send2trash.compat import PY3 +from configparser import ConfigParser +from tempfile import mkdtemp, NamedTemporaryFile, mktemp +import shutil +import stat +import sys +# Could still use cleaning up. But no longer relies on ramfs. + +HOMETRASH = send2trash.plat_other.HOMETRASH + +def touch(path): + with open(path, 'a'): + os.utime(path, None) + +class TestHomeTrash(unittest.TestCase): + def setUp(self): + self.file = NamedTemporaryFile( + dir=op.expanduser("~"), prefix='send2trash_test', delete=False) + + def test_trash(self): + s2t(self.file.name) + self.assertFalse(op.exists(self.file.name)) + + def tearDown(self): + name = op.basename(self.file.name) + os.remove(op.join(HOMETRASH, 'files', name)) + os.remove(op.join(HOMETRASH, 'info', name+'.trashinfo')) + + +def _filesys_enc(): + enc = sys.getfilesystemencoding() + # Get canonical name of codec + return codecs.lookup(enc).name + +@unittest.skipIf(_filesys_enc() == 'ascii', 'ASCII filesystem') +class TestUnicodeTrash(unittest.TestCase): + def setUp(self): + self.name = u'send2trash_tést1' + self.file = op.join(op.expanduser(b'~'), self.name.encode('utf-8')) + touch(self.file) + + def test_trash_bytes(self): + s2t(self.file) + assert not op.exists(self.file) + + def test_trash_unicode(self): + s2t(self.file.decode(sys.getfilesystemencoding())) + assert not op.exists(self.file) + + def tearDown(self): + if op.exists(self.file): + os.remove(self.file) + + trash_file = op.join(HOMETRASH, 'files', self.name) + if op.exists(trash_file): + os.remove(trash_file) + os.remove(op.join(HOMETRASH, 'info', self.name+'.trashinfo')) + +# +# Tests for files on some other volume than the user's home directory. +# +# What we need to stub: +# * plat_other.get_dev (to make sure the file will not be on the home dir dev) +# * os.path.ismount (to make our topdir look like a top dir) +# +class TestExtVol(unittest.TestCase): + def setUp(self): + self.trashTopdir = mkdtemp(prefix='s2t') + if PY3: + trashTopdir_b = os.fsencode(self.trashTopdir) + else: + trashTopdir_b = self.trashTopdir + self.fileName = 'test.txt' + self.filePath = op.join(self.trashTopdir, self.fileName) + touch(self.filePath) + + self.old_ismount = old_ismount = op.ismount + self.old_getdev = send2trash.plat_other.get_dev + def s_getdev(path): + from send2trash.plat_other import is_parent + st = os.lstat(path) + if is_parent(self.trashTopdir, path): + return 'dev' + return st.st_dev + def s_ismount(path): + if op.realpath(path) in (op.realpath(self.trashTopdir), op.realpath(trashTopdir_b)): + return True + return old_ismount(path) + + send2trash.plat_other.os.path.ismount = s_ismount + send2trash.plat_other.get_dev = s_getdev + + def tearDown(self): + send2trash.plat_other.get_dev = self.old_getdev + send2trash.plat_other.os.path.ismount = self.old_ismount + shutil.rmtree(self.trashTopdir) + +class TestTopdirTrash(TestExtVol): + def setUp(self): + TestExtVol.setUp(self) + # Create a .Trash dir w/ a sticky bit + self.trashDir = op.join(self.trashTopdir, '.Trash') + os.mkdir(self.trashDir, 0o777|stat.S_ISVTX) + + def test_trash(self): + s2t(self.filePath) + self.assertFalse(op.exists(self.filePath)) + self.assertTrue(op.exists(op.join(self.trashDir, str(os.getuid()), 'files', self.fileName))) + self.assertTrue(op.exists(op.join(self.trashDir, str(os.getuid()), 'info', self.fileName + '.trashinfo'))) + # info relative path (if another test is added, with the same fileName/Path, + # then it gets renamed etc.) + cfg = ConfigParser() + cfg.read(op.join(self.trashDir, str(os.getuid()), 'info', self.fileName + '.trashinfo')) + self.assertEqual(self.fileName, cfg.get('Trash Info', 'Path', raw=True)) + +# Test .Trash-UID +class TestTopdirTrashFallback(TestExtVol): + def test_trash(self): + touch(self.filePath) + s2t(self.filePath) + self.assertFalse(op.exists(self.filePath)) + self.assertTrue(op.exists(op.join(self.trashTopdir, '.Trash-' + str(os.getuid()), 'files', self.fileName))) + +# Test failure +class TestTopdirFailure(TestExtVol): + def setUp(self): + TestExtVol.setUp(self) + os.chmod(self.trashTopdir, 0o500) # not writable to induce the exception + + def test_trash(self): + with self.assertRaises(OSError): + s2t(self.filePath) + self.assertTrue(op.exists(self.filePath)) + + def tearDown(self): + os.chmod(self.trashTopdir, 0o700) # writable to allow deletion + TestExtVol.tearDown(self) + +# Make sure it will find the mount point properly for a file in a symlinked path +class TestSymlink(TestExtVol): + def setUp(self): + TestExtVol.setUp(self) + # Use mktemp (race conditioney but no symlink equivalent) + # Since is_parent uses realpath(), and our getdev uses is_parent, + # this should work + self.slDir = mktemp(prefix='s2t', dir=op.expanduser('~')) + + os.mkdir(op.join(self.trashTopdir, 'subdir'), 0o700) + self.filePath = op.join(self.trashTopdir, 'subdir', self.fileName) + touch(self.filePath) + os.symlink(op.join(self.trashTopdir, 'subdir'), self.slDir) + + def test_trash(self): + s2t(op.join(self.slDir, self.fileName)) + self.assertFalse(op.exists(self.filePath)) + self.assertTrue(op.exists(op.join(self.trashTopdir, '.Trash-' + str(os.getuid()), 'files', self.fileName))) + + def tearDown(self): + os.remove(self.slDir) + TestExtVol.tearDown(self) + +if __name__ == '__main__': + unittest.main() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/tests/test_plat_win.py new/Send2Trash-1.5.0/tests/test_plat_win.py --- old/Send2Trash-1.4.1/tests/test_plat_win.py 1970-01-01 01:00:00.000000000 +0100 +++ new/Send2Trash-1.5.0/tests/test_plat_win.py 2018-02-16 15:40:05.000000000 +0100 @@ -0,0 +1,46 @@ +# coding: utf-8 +import os +import sys +import unittest +from os import path as op +from tempfile import gettempdir + +from send2trash import send2trash as s2t + + +@unittest.skipIf(sys.platform != 'win32', 'Windows only') +class TestLongPath(unittest.TestCase): + def setUp(self): + filename = 'A' * 100 + self.dirname = '\\\\?\\' + os.path.join(gettempdir(), filename) + self.file = os.path.join( + self.dirname, + filename, + filename, # From there, the path is not trashable from Explorer + filename, + filename + '.txt') + self._create_tree(self.file) + + def tearDown(self): + try: + os.remove(self.dirname) + except OSError: + pass + + def _create_tree(self, path): + dirname = os.path.dirname(path) + if not os.path.isdir(dirname): + os.makedirs(dirname) + with open(path, 'w') as writer: + writer.write('Looong filename!') + + def test_trash_file(self): + s2t(self.file) + self.assertFalse(op.exists(self.file)) + + @unittest.skipIf( + op.splitdrive(os.getcwd())[0] != op.splitdrive(gettempdir())[0], + 'Cannot trash long path from other drive') + def test_trash_folder(self): + s2t(self.dirname) + self.assertFalse(op.exists(self.dirname)) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Send2Trash-1.4.1/tox.ini new/Send2Trash-1.5.0/tox.ini --- old/Send2Trash-1.4.1/tox.ini 1970-01-01 01:00:00.000000000 +0100 +++ new/Send2Trash-1.5.0/tox.ini 2017-08-04 02:27:29.000000000 +0200 @@ -0,0 +1,11 @@ +[tox] +envlist = py27,py34,py35,py36 +skip_missing_interpreters = True + +[testenv] +commands = + python setup.py test + +[testenv:py27] +deps = + configparser ++++++ python2.patch ++++++ >From 74352462f5df2cb5708b96458b81afef3070c800 Mon Sep 17 00:00:00 2001 From: Virgil Dupras <hs...@hardcoded.net> Date: Thu, 26 Jul 2018 08:30:39 -0400 Subject: [PATCH] Fix broken tests on py2 --- tests/test_plat_other.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_plat_other.py b/tests/test_plat_other.py index b94295d..ae4f391 100644 --- a/tests/test_plat_other.py +++ b/tests/test_plat_other.py @@ -6,7 +6,11 @@ import send2trash.plat_other from send2trash.plat_other import send2trash as s2t from send2trash.compat import PY3 -from configparser import ConfigParser +try: + from configparser import ConfigParser +except ImportError: + # py2 + from ConfigParser import ConfigParser from tempfile import mkdtemp, NamedTemporaryFile, mktemp import shutil import stat