After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 789328 - Trash restore moves files to wrong location
Trash restore moves files to wrong location
Status: RESOLVED FIXED
Product: gvfs
Classification: Core
Component: trash backend
1.28.x
Other Linux
: Normal normal
: ---
Assigned To: Allison Karlitskaya (desrt)
gvfs-maint
Depends on:
Blocks:
 
 
Reported: 2017-10-22 23:34 UTC by dpantel
Modified: 2017-12-14 14:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
trash: Fix trash::orig-path for relative paths (4.31 KB, patch)
2017-10-24 07:48 UTC, Ondrej Holy
committed Details | Review

Description dpantel 2017-10-22 23:34:44 UTC
When using "restore" from the Gnome trash can, instead of moving the item to the original location, it's moved inside the .Trash directory.  This only happens on additionally-mounted drives (i.e. / and /home work fine).

Example follows:

mount point: /mnt/data
my user id: 1000
trash location: /mnt/data/.Trash

"trashing" file /mnt/data/example_path/example_file moves it to /mnt/data/.Trash/1000/files/example_file

The file appears in the Gnome trashcan with the correct original path listed.

restoring the file from Gnome trashcan moves it to /mnt/data/.Trash/example_path/example_file

Of note, when the file is in the .Trash, the info file has a relative path:

[Trash Info]
Path=example_path/example_file
DeletionDate=2017-10-20T17:18:29

On another note, installing trash-cli and using restore-trash works as expected, so maybe the relative path is not the issue, just the restore functionality of gvfs.
Comment 1 Ondrej Holy 2017-10-23 12:27:09 UTC
Thanks for your report, is trash::orig-path attribute also wrong? 
gvfs-info -a "trash::orig-path" trash:///[the_problematic_file]
Comment 2 dpantel 2017-10-24 01:02:21 UTC
$ gvfs-info -a "trash::orig-path" trash:///example_file
Error getting info: No such file or directory
Comment 3 Ondrej Holy 2017-10-24 07:47:33 UTC
Ah, sorry, it happens probably only with non-home trashes, where the URIs need to be escaped correctly, which is not obvious... nevermind.

Just for info, the correct URI can be found using the following:
$ gvfs-ls trash:///
trash:///%5Crun%5Cmedia%5Coholy%5CBE41-EC1C%5C.Trash%5C1000%5Cfiles%5Cempty.txt

...and then can be used for e.g. gvfs-info:
$ gvfs-info trash:///%5Crun%5Cmedia%5Coholy%5CBE41-EC1C%5C.Trash%5C1000%5Cfiles%5Cempty.txt
uri: trash:///%5Crun%5Cmedia%5Coholy%5CBE41-EC1C%5C.Trash%5C1000%5Cfiles%5Cempty.txt
attributes:
  trash::orig-path: /run/media/oholy/BE41-EC1C/.Trash/empty.txt

...the orig-path is obviously wrong in case of trash dir which consists of more directories, i.e. ".Trash/$UID", though it works correctly for trashes in form of ".Trash-$UID". GIO uses the latter form preferably, so that's  probably the reason why the bug was not found earlier...
Comment 4 Ondrej Holy 2017-10-24 07:48:16 UTC
Created attachment 362149 [details] [review]
trash: Fix trash::orig-path for relative paths

The trash::orig-path attribute calucaltion expects that the trash
is only one dir (i.e. .Trash, .Trash-$UID) and it fails for relative
paths in case it is not (i.e. .Trash/$UID). Let's propagate the topdir
and fix relative path handling...
Comment 5 Ondrej Holy 2017-10-24 07:49:35 UTC
Don't you have a chance to test the attached patch?
Comment 6 dpantel 2017-10-25 01:28:22 UTC
I think you're on the right track...

$ gvfs-info -a "trash::orig-path" trash:///%5Cmnt%5data%5C.Trash%5C1000%5Cfiles%5Cexample_file

attributes:
  trash::orig-path: /mnt/data/.Trash/example_path/example_file

I don't know if I can help you test the patch without some direction as to what/how to compile with the patch and where to stick the result...
Comment 7 dpantel 2017-10-28 22:09:08 UTC
compiled gvfs with patch.
No fix.  Same exact result as above
Comment 8 Ondrej Holy 2017-10-30 08:59:53 UTC
I don't know how did you build the gvfs sources and where did you install them. But I suppose that the main gvfs daemon doesn't see the newly built gvfsd-trash binary and the system version is running instead. Check the path using "ps ax | grep gvfsd-trash". Probably the easiest way of testing is to run the newly built gvfsd-trash daemon from builddir manually: "pkill gvfsd-trash; ./daemon/gvfsd-trash". Does it help? What distribution do you have? (I have to write down some notes for testers finally).
Comment 9 dpantel 2017-12-12 01:26:44 UTC
Sorry for disappearing.

I have re-tried compiling gfvs from source with your patch and replacing gvfsd-trash and gvfs-trash with resulting binaries.

Unfortunately, I was unable to test for the bug because, replacing the binaries caused other errors:

org.gtk.vfs.Daemon[1794]: mkdir: cannot create directory ‘/usr/lib/gvfs/.libs’: Permission denied
org.gtk.vfs.Daemon[1794]: /usr/bin/ld: cannot open output file /usr/lib/gvfs/.libs/4327-lt-gvfsd-trash: No such file or directory
org.gtk.vfs.Daemon[1794]: collect2: error: ld returned 1 exit status

I would not doubt that this was caused by some error that I made, although the compilation process when fine, as far as I can tell.

Distro: Linux Mint 18.2	(Ubuntu 16.04), Cinnamon DE.

Thanks.
Comment 10 Ondrej Holy 2017-12-12 07:34:42 UTC
So please don't replace anything and just run the backend from builddir as noted in Comment 8, this is some linker error caused by moving the binaries to another place...
Comment 11 dpantel 2017-12-12 19:03:38 UTC
Oops... I did not follow directions well.  I have now retested with the patched gvfsd-trash and it worked!


$ gvfs-info -a "trash::orig-path" trash:///%5Cmnt%5data%5C.Trash%5C1000%5Cfiles%5Cexample_file

attributes:
  trash::orig-path: /mnt/data/example_path/example_file


Restore worked as intended.
Comment 12 Ondrej Holy 2017-12-13 08:16:11 UTC
Thanks for testing!

Attachment 362149 [details] pushed as b77ad0a - trash: Fix trash::orig-path for relative paths
Comment 13 Ondrej Holy 2017-12-13 08:18:15 UTC
Pushed to stable as well.
Comment 14 dpantel 2017-12-13 22:51:14 UTC
Thank you.
Is there a relatively easy way to compile gvfsd-trash in such a way that it works as a replacement for my current bin? (without the linker errors?)
Comment 15 Ondrej Holy 2017-12-14 14:06:48 UTC
You can create symlink instead of copying, or modify exec line in /usr/share/gvfs/mounts/trash.mount file to point to your builddir executable for example.
Comment 16 Ondrej Holy 2017-12-14 14:09:40 UTC
Or you can, of course, install the custom build into system paths...
Comment 17 Ondrej Holy 2017-12-14 14:10:40 UTC
It would be best to add patch into your distro package...