@@ -492,13 +492,28 @@ def delete_file(self, path):
492
492
if not os .path .exists (os_path ):
493
493
raise web .HTTPError (404 , u'File or directory does not exist: %s' % os_path )
494
494
495
+ def _check_trash (os_path ):
496
+ if sys .platform in {'win32' , 'darwin' }:
497
+ return True
498
+
499
+ # It's a bit more nuanced than this, but until we can better
500
+ # distinguish errors from send2trash, assume that we can only trash
501
+ # files on the same partition as the home directory.
502
+ file_dev = os .stat (os_path ).st_dev
503
+ home_dev = os .stat (os .path .expanduser ('~' )).st_dev
504
+ return file_dev == home_dev
505
+
495
506
if self .delete_to_trash :
496
- self .log .debug ("Sending %s to trash" , os_path )
497
- # Looking at the code in send2trash, I don't think the errors it
498
- # raises let us distinguish permission errors from other errors in
499
- # code. So for now, just let them all get logged as server errors.
500
- send2trash (os_path )
501
- return
507
+ if _check_trash (os_path ):
508
+ self .log .debug ("Sending %s to trash" , os_path )
509
+ # Looking at the code in send2trash, I don't think the errors it
510
+ # raises let us distinguish permission errors from other errors in
511
+ # code. So for now, just let them all get logged as server errors.
512
+ send2trash (os_path )
513
+ return
514
+ else :
515
+ self .log .warning ("Skipping trash for %s, on different device "
516
+ "to home directory" , os_path )
502
517
503
518
if os .path .isdir (os_path ):
504
519
listing = os .listdir (os_path )
0 commit comments