We created a synchronizer plugin for discourse and it should synchronize backups to the google drive service account.
In order to keep the admin's google drive account clutterfree, we built a method at the end of the synchronizer, that is called remove_old_files
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 before in an instance variable. So with session.files we get an array of all the files in our google drive account. In the sorted variable we sort them from new to old. In the keep variable we take the first few (the admin hat to set the quantity) and in the trash variable we define the rest. Until here the method works in the console.
Now in the documentation for the Google Drive gem there is a delete method for the File object:
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 delete via the rails console, it tells me Success - nil as if everything went fine. But ! the files are still there when I count them or call them. Even though I tried to delete them setting permanent = true :/
Why doesn't google delete the old backup files?