4 ms·
> For example, if we rsync -a /source /target, we trust that the contents of /target will exactly match the contents of /source You might trust that, but you'd
by wtbob 10y ago
> For example, if we rsync -a /source /target, we trust that the contents of /target will exactly match the contents of /source
You might trust that, but you'd be wrong:
$ cd /tmp
$ mkdir foo
$ cd foo
$ mkdir bar
$ mkdir baz
$ touch bar/quux
$ rsync -a ./bar ./baz
$ ls baz
bar
$ ls -R baz
baz:
bar
baz/bar:
quux
You see, without a final '/' rsync will put the source into the target, rather than synchronising the source and the target. Also, if you really want a sync as opposed to just a full copy, you probably want to add --delete (which will delete files in the target which don't exist in the source.
So you probably want rsync -a --delete source/ target/.
- mjaniczek 10y agoThat would make for a great property-based test. It would be interesting to see the minimal counter-examples to widely-believed properties that don't hold (not just for rsync but for dfferent CLI tools). (See John Hughes, testing Dropbox with QuickCheck: https://vimeo.com/158002499 https://vimeo.com/158002499) EDIT: s/Jon/John/
- zeveb 10y agoIncidentally, given the directory structure above, here's a good way to calculate sha256 checksums over the files. It shells out rather than use the IRONCLAD package to calculate the checksums. (let ((src #P"/tmp/foo/bar/") (dst #P"/tmp/foo/baz/")) (flet ((sha256sum (path) "Return the SHA256 checksum of PATH as a string (which is good enough for our purposes here)." (first (split-sequence:split-sequence #\Space (uiop:run-program `("sha256sum" ,(namestring path)) :output :string))))) (loop for src-path in (directory (uiop:merge-pathnames* "**/*.*" src)) for dst-path = (uiop:merge-pathnames* (uiop:subpathp src-path src) dst) for file = (uiop:truename* dst-path) if file when (uiop:file-pathname-p file) do (unless (string= (sha256sum src-path) (sha256sum dst-path)) (warn "~a does not match ~a" dst-path src-path)) end else do (warn "~a not found" dst-path))))