sisong / HDiffPatch

a C\C++ library and command-line tools for Diff & Patch between binary files or directories(folder); cross-platform; runs fast; create small delta/differential; support large files and limit memory requires when diff & patch.
Other
1.52k stars 280 forks source link

option to use hard links with hpatch #339

Closed Ost3rbaer closed 1 year ago

Ost3rbaer commented 1 year ago

It would be nice if we can avoid to copy same files upon creation of a patched output directory on the same file system as the source, i.e. use the functions link(2) on POSIX platforms (Linux/Android/OSX) and the CreateHardLinkA function (https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createhardlinka) on Windows platforms.

This has the potential of drastically reduce patch time and disk space requirements when only a subset of files in a larger project changes.

sisong commented 1 year ago

yes, you can do that.
dir patch step 1: patch new files & changed old files to dst dir. step 2: copy same old files to dst dir.
note func: _copySameFile() read old file's data copy to new file, _tempDir_copySameFile() only readed old file's data (for checksum)

other: linked file is safe? edit old file, will the new file be changed or copied?

Ost3rbaer commented 1 year ago

hard links share the file resource, so any changes on the original file will modify the linked file as well. Under Linux with COW file systems this can be changed with reference links if the underlying filesystem supports it (BTRFS or newer versions of XFS).

Under Windows hard links are only supported by NTFS - but FAT is dying anyways.

As there are some strings attached and is is a change in semantics I think it would be good if this feature rewuires an extra command line switch, e.g -l or -h

for reflinks (linux 4.5 and newer) have a look at https://man7.org/linux/man-pages/man2/ioctl_ficlonerange.2.html

sisong commented 1 year ago

"This library does not deal with file metadata" I don't want to support link files, you can extend this library youself if needed.