-
-
Save ACUVE/a02916fa977f045fc70b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'shellwords' | |
HASHFILE = 'sha512' | |
BASEPATH = 'realfiles' | |
REFFILE = 'reffile.ref' | |
alllist = {} | |
File.open(HASHFILE) do |file| | |
file.readlines.each do |line| | |
m = line.match(/^([0-9a-f]+) (.+)$/) | |
exit(-1) unless m | |
hash = m[1] | |
filename = File.join(BASEPATH, m[2]) | |
alllist[hash] = (alllist[hash] || []) << filename | |
end | |
end | |
alllist.each_pair do |k, v| | |
next unless v.size > 1 | |
srcfile = v[0] | |
v.drop(1).each do |file| | |
puts file | |
shell = Shellwords.shelljoin(['touch', '-r', file, REFFILE]) | |
`#{shell}` | |
shell = Shellwords.shelljoin(['cp', '--reflink=always', srcfile, file]) | |
`#{shell}` | |
shell = Shellwords.shelljoin(['touch', '-r', REFFILE, file]) | |
`#{shell}` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment