08-27-2012 10:02 AM
When I use CopyFile() to copy a file from a local directory to a UNC like \\ohtherCompute\file.ext, the destination file is occasionally corrupted.
// insert the new file. cviresult = CopyFile( "myFile.ext", "\\\\othercomputer\\share\\myFile.ext");
The value returned as cviresults is 0 even when the destination file is corrupted.
08-28-2012 06:37 AM
Is the destination a SMB/CIFS/Samba share or is it a VirtualBox share ? I've had problems with those in CVI (and other apps as some NTFS attributes seem to be forgotten and lead to file corruption).
08-28-2012 07:48 AM
The share is SMB from a native application no virtual box, or non-Microsoft OS in the connection. It is a Windows to Windows transfer.
08-28-2012 09:30 AM
Which version of CVI Runtime Engine are you using? You can find this by looking at the File Version of cvirte.dll in your system folder.
You could try using the Windows SDK CopyFileA function instead of the CVI CopyFile function and see if that works better - to do this, you must include windows.h as the first #include in your .c file. For example:
#include <windows.h>
/* other #include directives */
/* other code */
result = CopyFileA(your_src_path, your_dest_path, bOverwriteIfExists);
/* other code */
You can find more information about this function here:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa363851(v=vs.85).aspx
08-28-2012 09:46 AM
I'm using CVI 2012.
Thanks for the suggestion.
Using Window version of copy file is certainly a solution.
But I would like to know if this is a know/reported problem or if I am using the command wrong.
08-28-2012 04:20 PM - edited 08-28-2012 04:20 PM
No, this is not currently a known issue. This is the first report I can find of this issue. Thank you for reporting!
In order to resolve this with the CVI function, we will need to reproduce at NI. This might be a difficult task. How frequently is "occasionally"? Is there any consistency to the corruption occurrence? Are you copying the same file over and over, or are there multiple files that can become corrupted?
It might be that this is not related to the network shared location at all. What if you did two copies each time, copy to a local location and to a network location. See if the local copy is ever corrupted, and if it is, are both the local and the network copy corrupted at the same time.
Also, how large of a file is this? And what happens when it is corrupted; does it have no data, part of the data, or just a couple bytes are off?
If you have a sample file to send (both corrupt and not corrupt), that may help as well.
08-29-2012 10:01 AM
It happens about 50% of the time.
We do have 3 copies of the corrupted files. In the case where we looked at the content, the file contained data that was not from the file we sent. This may indicated that the directory entry was made and space reserved, but the copy did not happen.
Our code does the following:
Check to see if the destination file exists because it may be busy at the time. If it does, then attempt to rename the destination file to a .bak.
To rename the file, we first look for any preexisting bak file by the desired bak file name, and try to delete the old bak file.
Once we know we do not have an out of date bak file we do the rename.
We then copy the desired file.
If any of the preceding fails, we report the error to the user.
In each case the code completes successfully, but the file on the destination is corrupt.
08-31-2012 05:06 PM
So I made an automated test for this and did some pretty extensive testing. I could not reproduce any file corruptions.
Is it possible that you have spotty network connectivity? Or are there multiple applications accessing the same file at the same time?
09-04-2012 07:43 AM
The transfer is on a single use network, so only one host/client at the time so no one else would be accessing the file in theory. Also the network is very short distance so low likelihood that it is "flakey". Once the files have been distributed, then the network has the possibility of becoming very busy and we see no evidence of network failures in the normal use mode.
We are hosting on a Windows XP and the clients are all Windows CE 6.0. The network is 10/100/1GB through a Netgear Switch on a private physical network. Not much opportunity for outside interference. Oh by the way, our IT policy would not allow the Windows XP machine to route requests from our backbone to the private network so little or no chance that any computer other than the host could access the CE system or its files, so I don't think it could be any one else accessing the file.