0

I have a content provider which has a _data column, the _data column stores a reference to a created file, when the row is deleted the file sometimes gets left behind.

What would be the best way to find and delete the orphaned files, which are currently not referenced by the SQLite database?

The only solution I can think of is iterating through the files in the image storage directory, and checking if the file exists in the database, however this seems to be slow as it will require multiple queries to the database;

bsagal
  • 591
  • 1
  • 4
  • 10

1 Answers1

0

The only solution I can think of is iterating through the files in the image storage directory, and checking if the file exists in the database, however this seems to be slow as it will require multiple queries to the database;

There's no better way, because you want to remove files you do not know about. So you first have to learn about their existence, and scanning folders is the only way

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141