EldoS | Feel safer!

Software components for data protection, secure storage and transfer

RenameOrMoveFile behavior w/ existing destination

Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.
#32052
Posted: 02/02/2015 17:55:33
by CopyAgent Team (Priority Standard support level)
Joined: 08/31/2014
Posts: 6

Hi,

I was hoping I could get some clarification on expected behavior of OnRenameOrRemoveFile callbacks. It seems to be abstracted a little such that both MoveFile and MoveFileEx Win32 functions will result in it being called.

According to MSDN docs, MoveFile does not allow the destination path to exist. Neither does MoveFileEx, unless the MOVEFILE_REPLACE_EXISTING flag is passed in. Keeping this in mind, how should we be implementing OnRenameOrRemoveFile to most accurately mimic NTFS behavior?

For some context, we first implemented it such that we threw an error if the destination path already existed. However, some Windows applications seem to expect the destination to be overwritten.

Thanks.
#32055
Posted: 02/03/2015 02:06:24
by Volodymyr Zinin (EldoS Corp.)

In order to simplify the OnRenameFile callback the MOVEFILE_REPLACE_EXISTING flag is processed by CBFS internally. So if the OnRenameFile callback is called your code should always rename/move the file not depending on whether the destination file exists or not.
#32070
Posted: 02/03/2015 07:16:36
by CopyAgent Team (Priority Standard support level)
Joined: 08/31/2014
Posts: 6

Cool, thanks! Quick follow up question.

The MoveFileEx documentation says, regarding MOVEFILE_REPLACE_EXISTING, "This value cannot be used if lpNewFileName or lpExistingFileName names a directory." Should we be checking for this conflict case, or will CBFS not even translate the action into a rename if one of the paths is as dir?
#32075
Posted: 02/03/2015 07:47:06
by Volodymyr Zinin (EldoS Corp.)

You shouldn't check for this. CBFS itself checks everything necessary for MOVEFILE_REPLACE_EXISTING and either completes renaming with error or calls the OnRename callback when the destination file (or directory) is allowed to be replaced. Although even if the OnRename callback is called you can still return error from the callback and this causes the operation to be canceled with this error.
But again if the OnRename callback is called it means that the source file (or directory) is allowed to be renamed and it isn't necessary to check from you code whether the destination file/directory exists or not.
#37351
Posted: 08/01/2016 06:28:34
by Jacky Lee (Standard support level)
Joined: 10/24/2014
Posts: 11

Hi,

I have called MoveFileEx with the flag MOVEFILE_REPLACE_EXISTING, but CBFS does not call OnRenameOrRemoveFile, and the result of GetLastError is 183(ERROR_ALREADY_EXISTS).
What does CBFS check for ERROR_ALREADY_EXISTS?

Thanks.
#37352
Posted: 08/01/2016 06:28:57
by Jacky Lee (Standard support level)
Joined: 10/24/2014
Posts: 11

Quote
Jacky Lee wrote:
Hi,

I have called MoveFileEx with the flag MOVEFILE_REPLACE_EXISTING, but CBFS does not call OnRenameOrRemoveFile, and the result of GetLastError is 183(ERROR_ALREADY_EXISTS).
What does CBFS check for MOVEFILE_REPLACE_EXISTING?

Thanks.


What does CBFS check for MOVEFILE_REPLACE_EXISTING?
#37353
Posted: 08/01/2016 08:18:11
by Volodymyr Zinin (EldoS Corp.)

Is the problem reproducible with one of the CBFS samples? Also if CBFS version is older than 6.1.180 then try to use the last one. It was a bug before which could cause similar behavior.

Thanks.
Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.

Reply

Statistics

Topic viewed 2039 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!