Skip to content

Commit

Permalink
fix: don't keep recently accessed files during housekeeping
Browse files Browse the repository at this point in the history
I have just unpacked an old backup,
changed the setting delete_device_after
and tried to export a backup.
This did not delete anything
because all files were considered recent
by their atime and crtime.

Here is an example file statistics right after unpacking a backup:
$ stat image_2021-03-06_21-40-28.jpg
  File: image_2021-03-06_21-40-28.jpg
  Size: 66715           Blocks: 136        IO Block: 4096   regular file
Device: 254,3   Inode: 5338300     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/    user)   Gid: ( 1000/    user)
Access: 2023-11-28 14:00:12.436093996 +0000
Modify: 2021-03-13 18:21:28.000000000 +0000
Change: 2023-11-28 13:57:56.641835196 +0000
 Birth: 2023-11-28 13:57:56.641835196 +0000

atime is updated simply by opening a file,
it is not a good time reference e.g.
if user just viewed old media
and then enabled deletion of files from device.

mtime is the right thing to check,
it is the time blob was written to the disk,
this commit keeps this check.

ctime is the time of metadata modification,
such as permission changes,
we are not interested in this.

crtime is not even standardized
and not implemented by some filesystems.
In my case it is the time when I unpacked the backup,
while the file in the backup is actually old.
  • Loading branch information
link2xt committed Nov 28, 2023
1 parent 9e7e172 commit 58ad780
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,18 +889,11 @@ pub async fn remove_unused_files(context: &Context) -> Result<()> {
continue;
}
unreferenced_count += 1;
let recently_created =
stats.created().map_or(false, |t| t > keep_files_newer_than);
let recently_modified = stats
.modified()
.map_or(false, |t| t > keep_files_newer_than);
let recently_accessed = stats
.accessed()
.map_or(false, |t| t > keep_files_newer_than);

if p == blobdir
&& (recently_created || recently_modified || recently_accessed)
{
if p == blobdir && recently_modified {
info!(
context,
"Housekeeping: Keeping new unreferenced file #{}: {:?}.",
Expand Down

0 comments on commit 58ad780

Please sign in to comment.