file.renameTo
method returns false, in docker container
. I am using PVC
in container instance.
I tried removing PVC, then it works fine, but when I use PVC then returns false
Returns false means file is not getting moved or renamed 😐.
In my case, the file is moved from PVC
location into the docker container specified location.
When we enable PVC
on Kubernetes
cluster then storage is on a different filesystem
.
I think this issue is related to file move from one filesystem to another file system. because when PVC is not enabled then file.renameTo
works fine, but when PVC is enabled then it fails.
So my question is what are the possible ways to fix this. I cannot disable PVC
so what is the possible solution to move a file from one filesystem to another.
As per my assumption, when we use PVC
then your storage is at a different location and your docker container is at a different location.
So file move, in this case, is a bit complex. The solution I used, in this case, is file copy and paste at the destination location.
public void copyFile(File pvcFileLocation, File dockerContainerLocation){
FileInputStream inputStream = new FileInputStream(pvcFileLocation);
FileOutputStream outputStream = new FileOutputStream(dockerContainerLocation);
int b = -1;
while ((b = inputStream.read()) != -1) {
outputStream.write(b);
}
inputStream.close();
outputStream.close();
}