File size

harakim harakim at gmail.com
Mon Aug 21 07:52:28 UTC 2023


I have been doing some backups and I wrote a utility that 
determines if files are an exact match. As a shortcut, I check 
the file size. So far so good on this with millions of files 
until I found something odd: getSize() and DirEntry's .size are 
producing different values.

This is the relevant code:
```
	if (sourceFile.size != getSize(destinationFilename)) {
		if (getSize(sourceFile.name) != getSize(destinationFilename))
			writeln("Also did not match");
		else
			writeln("Did match so this is odd");

		return ArchivalStatus.SizeDidNotMatch;
	}
```

Whereas before it just returned SizeDidNotMatch, now it also 
prints "Did match so this is odd".

It seems really odd that getSize(sourceFile.name) is returning a 
different number than sourceFile.size. This is an external HDD on 
windows formatted in ntfs that it is reading. I believe I 
originally wrote the files to the file system in Windows, but 
then today I cut and paste them (in the same drive) in Linux. 
However, this is the first time this has happened after millions 
of comparisons and it only happened for about 6 files. It does 
happen consistently though.

I have verified that the file size is that reported by getSize 
and not sourceFile.size and that the files open correctly.

This is my compiler version:
DMD32 D Compiler v2.104.2-dirty

If this is actually a problem and I'm not missing something, I 
would not mind trying to fix this whenever I have some time.


More information about the Digitalmars-d-learn mailing list