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

set file's trashed attribute to true instead of permanently removing it #178

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

robeeeert
Copy link

@robeeeert robeeeert commented Apr 11, 2017

This is a PR for issue #177
I wasn't able to test it though, because I couldn't setup my debugging environment.
Also, it is not configurable by FUSE variables yet.

So, if anybody is interested in this, please feel free to expand on this or provide me with suggestions on how to improve it :)

@dsoprea
Copy link
Owner

dsoprea commented Apr 11, 2017

Thank you. It was a good suggestion and I was hoping to see a PR.

You can use Vagrant to easily test it (vagrant/).

GDFS needs to maintain its current behavior and permanently delete files unless you turn it on via mount variables.

@robeeeert
Copy link
Author

Thanks for the vagrant hint. I tested it and found I used a deprecated method of trashing files, so I used the up-to-date function.

Concerning the variable: Would it be okay to use an environment variable like GD_DEBUG or do you prefer a FUSE variable? I'm asking since I don't have any experience with FUSE, so it could take a while until I can apply the changes.

@dsoprea
Copy link
Owner

dsoprea commented Apr 11, 2017 via email

@robeeeert
Copy link
Author

Yea, makes sense! Thank you for your guidance! :)

One last question, out of curiosity: Why should the default behavior be to delete the files and not to trash them? Is it only backwards-compatibility or is it by design?
I naively would argue it should default to trashing the files, since I don't see any downsides: Locally, the file is gone, but you still have the option to restore it from "the cloud", with "the cloud" acting as a backup system.

gdrivefs/conf.py Outdated
@@ -54,5 +57,7 @@ def get(key):
def set(key, value):
if key not in Conf.__dict__:
raise KeyError(key)
elif key is "delete_to_trash":
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In get() make sure to use an inequality, not is. is is only used when checking that one instance is the same as another. By contrast, creating two different objects (instances) from the same class should always return False. Note that string caching may create inconsistent results when comparing strings. Consequently, you should only use is for comparing False, True, and None.

@@ -770,10 +770,15 @@ def remove_entry(self, normalized_entry):

client = self.__auth.get_client()

args = { 'fileId': normalized_entry.id }
args = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should modify the existing function (remove_entry). We should be adding a new function called trash_entry. These hit two different APIs. Just update the existing references from remove_entry to trash_entry. Thanks. We're almost there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then I have to check for delete_to_trash before every call to remove_entry. Shouldn't we then have something like a delegate function that either calls remove_entry or trash_entry based on the variable's value?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tempted to agree, but two points I'd like to make:

  1. This module is a general API wrapper. There should be minimal intelligence. We should put branching logic in another module.
  2. There is always the chance that we'll have a need to either definitely trash things or definitely delete things, later. We can't not prevent us from being able to do that.

Please create a "gdutility" module in the same package (path) with a class called "GdUtility" and add a method called "smart_delete" that calls the appropriate method.

@dsoprea
Copy link
Owner

dsoprea commented Apr 11, 2017

Can you please remove the comment at https://github.com/dsoprea/GDriveFS/blob/master/gdrivefs/gdfs/gdfuse.py#L670?

@dsoprea
Copy link
Owner

dsoprea commented Apr 11, 2017

It was an oversight. Usually Unix filesystems at the console don't have a trash. On the other hand, maybe others assumed that it went into the trash but never mistakenly deleted anything important. For right now, let's just implement it and have some people test it. Then, we can adjust the default.

If a few people would like to volunteer to check that this works as expected, we can change the default after. Technically this is a break in backwards-compatibility, but since Google will GC the trashed items (and the quota won't be negatively affected for very long except for massive deletes, which is hardly the common use-case in GD) the risk is not very high.

@robeeeert
Copy link
Author

Hey, just wanted to know if you're still into this thing and if you're content with the proposed approach :)

Copy link
Owner

@dsoprea dsoprea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. I never submitted the review.

@@ -770,10 +770,15 @@ def remove_entry(self, normalized_entry):

client = self.__auth.get_client()

args = { 'fileId': normalized_entry.id }
args = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tempted to agree, but two points I'd like to make:

  1. This module is a general API wrapper. There should be minimal intelligence. We should put branching logic in another module.
  2. There is always the chance that we'll have a need to either definitely trash things or definitely delete things, later. We can't not prevent us from being able to do that.

Please create a "gdutility" module in the same package (path) with a class called "GdUtility" and add a method called "smart_delete" that calls the appropriate method.

@robeeeert
Copy link
Author

Alright, thanks! I'll continue this weekend :)

@robeeeert
Copy link
Author

Hi again, I moved the method into its own module. Are you sure we need a class for it? I considered declaring it a static method, since we don't need any state (hardly ever in a utility class generally I guess), and then discovered the "python way" was to simply implement it as a normal function.
What's your opinion on 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.

None yet

2 participants