Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track inodes and use them for hard link comparisons on linux #535

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions VDF.Core/FileEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public FileEntry(FileInfo fileInfo) {
DateCreated = fileInfo.CreationTimeUtc;
DateModified = fileInfo.LastWriteTimeUtc;
FileSize = fileInfo.Length;
if (CoreUtils.IsWindows) {
Inode = 0;
} else {
var ok = Mono.Unix.Native.Syscall.stat(_Path, out var stat);
if (ok == 0) {
Inode = stat.st_ino;
}
}
}

[ProtoMember(1)]
Expand Down Expand Up @@ -65,6 +73,8 @@ public string Path {
public DateTime DateModified;
[ProtoMember(8)]
public long FileSize;
[ProtoMember(9)]
public ulong Inode;

[ProtoIgnore]
internal bool invalid = true;
Expand Down
10 changes: 10 additions & 0 deletions VDF.Core/ScanEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,16 @@ void ScanForDuplicates() {
continue;
}

// Shortcut for linux, if the inodes are known and they are the same
// these two files are by definition hard links of each other
// no further inspection necessary
if (Settings.ExcludeHardLinks &&
entry.Inode > 0 &&
entry.Inode == compItem.Inode) {
isDuplicate = false;
break;
}


flags = DuplicateFlags.None;
isDuplicate = CheckIfDuplicate(entry, null, compItem, out difference);
Expand Down