I have the following Java code running in a media module:
File file = new File("/my/path/"+String.format("%02d", date)+"/"+streamAliasRef+".mp4");
// Destination directory
File dir = new File("/mnt/s3");
// Move file to new directory
boolean success = file.renameTo(new File(dir, file.getName()));
if (!success) {
getLogger().info("File failed to move to s3"+file.getName());
}
else {
getLogger().info("File moved to s3 successfully"+ file.getName());
}
For some reason I am consistently getting “File failed to move to s3”
I’m pretty new to Java, so forgive me if this is a simple problem. I know for a fact that both directories exist. One important note which may have something to do with it is I’m using Fuse to mount an S3 bucket to the filesystem.
In Java running on unix, renameTo only works if you are in the same file system. So if you are moving across filesystems, you will need to copy and delete the original. The unix mv command does this as well. This is why mv is instant on the same filesystem, but takes forever across filesystems. It detects the different filesystems and does a copy delete in that case.