There are some workarounds, but I wanted to raise an issue with the real thing.
I've an external server uploading files to /upload folder and I'm using java.nio.file.Files atomic move to copy them into /dest folder and then processing the moved files.
The issue is that it evident that after the call to nio move the source file is not yet flushed in the source but still move executed atomically and once it flushed it is flushed to the destination moved file.
OS is Ubuntu. Pseudo is:
Path origFilePath = resolveOrigFilePath();
Path targetFilePath = resolveOrigFilePath();
//logging shows empty file in source, length = 0
logger.warn("Atomic move file [{}], can read mode: [{}],can write mode: [{}] source size: [{}]",
origFilePath, origFilePath.toFile().canRead(), origFilePath.toFile().canWrite(), origFilePath
.toFile().length());
//execute atomic move of file
Path target = Files.move(origFilePath, targetFilePath, StandardCopyOption.ATOMIC_MOVE);
//logging shows empty file moved and original file is not exists anymore
logger.warn(
"Atomic moved file [{}] to [{}], target read mode: [{}], target write mode: [{}], target size: [{}], orig target size: [{}], is original exists [{}]",
origFilePath, target, target.toFile().canWrite(), target.toFile().canRead(),
target.toFile().length(), targetPath.toFile().length(), sensorFilePath.toFile().exists());
. . //processing the destination file which is still empty . . //after a short duration the destination file has content, while no other programatic access to the file is done
. .
Any idea what can be the reason in the underlying implementation?