I am currently developing a small application using Visual Studio, where I use the std::filesystem::copy function in order to copy a bunch of files from a network share. On this share, there is one particular file (an exe) that has given me a hard time. When this file is present, and I make a lot of clients do this copy statement from the share to their local disk, I often receive an error 32 (The process cannot access the file because it is being used by another process). The strange thing is that I do not even open the file; for now I only copy the file to local disk.
If I remove the file from the share, then there is no problem...
you cannot copy a file without opening it: the act of copying it means opening it to get the raw bytes to copy. Even if the OS is doing this for you, which I think is what filesystem does, it has to be opened unless its doing a raw disk sector type copy which it probably would not do.
that said, opening it read-only may be good enough to make this stop happening.
@jonnin: I do not see an option in std::filesystem::copy to open a file in read-only mode; I do however assume that they open the file in read-only mode by default?
@AbstractionAnon: On some of the clients there are no problems at all. I reboot all 10 clients which are connected to the server at the same time; they first copy the files of one share with big files and no problems at all (all at the same time). Afterwards they copy all files from a second share with smaller sizes and there I get the issue. Eventually mostly 2 or 3 devices are able to succesfully copy the necessary file.
@ne555: I receive this error on the clients which are accessing the server share.
I have also recompiled the exe, and now there is no error anymore. To further investigate why the original exe was not working, I made all clients copy the entire share at the same time using xcopy (Windows Cmd), and they have no problem at all to copy this exe.
If I place the original exe in the first (another) share and copy that share using std::filesystem::copy there is also no problem. I've checked all permissions on the file etc, but all seems okay to me.
Any further suggestions on what I can do to check why the copy function is not working properly with the original exe file?