Skip to content

Instantly share code, notes, and snippets.

@ACUVE

ACUVE/daburi.rb Secret

Created October 26, 2015 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ACUVE/a02916fa977f045fc70b to your computer and use it in GitHub Desktop.
Save ACUVE/a02916fa977f045fc70b to your computer and use it in GitHub Desktop.
#!/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