Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trashing on Linux #114

Merged
merged 2 commits into from Mar 8, 2021
Merged

Fix trashing on Linux #114

merged 2 commits into from Mar 8, 2021

Conversation

gsittyz
Copy link
Contributor

@gsittyz gsittyz commented Mar 6, 2021

Fixes #56 .

The changes are:

  1. DeletionDate should be written like %Y-%m-%dT%H:%M:%S in the local time.
  2. Write the trash info file completely before the file is moved to trash.

You can check the trash implementation in GNOME: https://gitlab.gnome.org/GNOME/glib/blob/glib-2-56/gio/glocalfile.c .

A code starting at line 2195 shows the appropriate style of trash info:

  {
    time_t t;
    struct tm now;
    t = time (NULL);
    localtime_r (&t, &now);
    delete_time[0] = 0;
    strftime(delete_time, sizeof (delete_time), "%Y-%m-%dT%H:%M:%S", &now);
  }

  data = g_strdup_printf ("[Trash Info]\nPath=%s\nDeletionDate=%s\n",
			  original_name_escaped, delete_time);

As for the second change, a comment starting at line 2181 is helpful. This comment and discussion ( https://bugzilla.gnome.org/show_bug.cgi?id=749314 ) shows the appropriate order of moveFile and writeFile.

  /* Write the full content of the info file before trashing to make
   * sure someone doesn't read an empty file.  See #749314
   */

I confirmed that the fixed code worked fine in Ubuntu 18.04. When I reverse the order of moveFile and writeFile in js, I always reproduce the hashed filename issue.


IssueHunt Summary

Referenced issues

This pull request has been submitted to:


@sindresorhus sindresorhus changed the title linux: fix to write an appropriate deletion date and avoid a hashed file name Fix trashing on Linux Mar 8, 2021
@sindresorhus sindresorhus merged commit 431cd71 into sindresorhus:main Mar 8, 2021
@sindresorhus
Copy link
Owner

Thanks for fixing this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trashing a file on Ubuntu Linux deletes it unrecoverably
2 participants