Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions gdrivefs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class Conf(object):
default_perm_file_editable = '666'
default_perm_file_noneditable = '444'

# Move files to trash instead of deleting them permanently
delete_to_trash = False

# How many extra entries to retrieve when an entry is accessed that is not
# currently cached.
max_readahead_entries = 10
Expand All @@ -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.

value = bool(int(value))

setattr(Conf, key, value)
11 changes: 9 additions & 2 deletions gdrivefs/gdtool/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,13 +769,20 @@ def remove_entry(self, normalized_entry):
_logger.info("Removing entry with ID [%s].", normalized_entry.id)

client = self.__auth.get_client()

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
}

delete_to_trash = gdrivefs.conf.Conf.get('delete_to_trash')

try:
result = client.files().trash(**args).execute()
if delete_to_trash:
_logger.debug("Moving file to trash")
result = client.files().trash(**args).execute()
else:
_logger.debug("Deleting file permanently")
result = client.files().delete(**args).execute()
except Exception as e:
if e.__class__.__name__ == 'HttpError' and \
str(e).find('File not found') != -1:
Expand Down