Shlomi Fish <shlo...@shlomifish.org> writes: >> > But if the size hasn't changed, then you still need to check something >> > else. You can do another light check, or decide to do the heavy one. >> > >> > This is also important because a hash-value is only a fingerprint, so >> > different files have (a small chance on having) the same hash value. >> > >> > The file size check makes the chance even smaller that you don't >> > detect the change. >> >> Hm ok, this kinda sucks ... Imagine I check size and mtime and I have >> a SHA-256 hash. Now there are the following cases: >> >> >> + mtime AND size changed: file has changed, put into report, update index >> >> + EITHER mtime changed, size is same, OR size changed, mtime is same: > > If the size changed, then the file definitely changed.
You could have the (odd) case that I look at the file, make a change, decide to undo it and in the process I somehow add some whitespace without noticing: The file changed size, but it didn't really change ;) >> How likely is it that the hash is the same though the file did change? > > Well, if you take SHA-256 for example, then its hash has 256 bits so you have > a > chance of 1 / (2**256) that two non-identical byte vectors will have the same > contents. > > shlomif@telaviv1:~$ perl -Mbigint -E 'say 2 ** 256' > 115792089237316195423570985008687907853269984665640564039457584007913129639936 > shlomif@telaviv1:~$ Hm that would be a really small chance :) As it's now, the script relies on size and mtime, i. e. when none of them change, the SHA-256 isn't considered. Changing a file without having the change detected would have to be done deliberately, and it could still be detected with a modified script, unless I'd also manage to keep the SHA-256 the same ... -- "Object-oriented programming languages aren't completely convinced that you should be allowed to do anything with functions." http://www.joelonsoftware.com/items/2006/08/01.html -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/