Delete files from Google Drive service account using gem drive gem
def remove_old_files
google_files = session.files
sorted = google_files.sort_by {|x| x.created_time}
keep = sorted.take(SiteSetting.discourse_sync_to_googledrive_quantity)
trash = google_files - keep
trash.each { |d| d.delete(true) }
end
we memoized the session object earlier in the instance variable. Thus, when session.files
we get an array of all the files in our Google account. In a variable, sorted
we sort them from new to old. In the variable keep
we take the first few (admin hat to set the quantity), and in the variable trash
we define the rest. So far, this method works in the console. There is now a method delete
for the File object in the documentation for the pearl of Google Drive :
File 'lib / google_drive / file.rb', line 182
def delete(permanent = false)
if permanent
@session.drive.delete_file(id)
else
@session.drive.update_file(id, { trashed: true }, {})
end
nil
end
But when I try to uninstall via rails console it tells me Success - nil
as if everything went well. But! the files still exist when I recalculate or call them. Even though I tried to remove them, install permanent = true
: / Why is google not removing old backup files?
source to share
No one has answered this question yet
Check out similar questions: