Skip to content
9 changes: 7 additions & 2 deletions gdrivefs/gdtool/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

'fileId': normalized_entry.id,
'body': {
'trashed': True
}
}

try:
result = client.files().delete(**args).execute()
result = client.files().update(**args).execute()
except Exception as e:
if e.__class__.__name__ == 'HttpError' and \
str(e).find('File not found') != -1:
Expand Down