EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Handle FileRename in Callback

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
Posted: 10/24/2013 17:49:04
by Andreas Pross (Standard support level)
Joined: 10/17/2013
Posts: 8

I have tried to rotate a Image by using Windows context menue. But without success. I noticed a strange behaviour of the file handling and now I am not sure if this is caused by some bug or if this is normal behaviour and I should handle this within the callbacks.

When rotating the Image, Windows creates a temporary file for the rotated image (mypic.jpg.tmp).
After this, a new temporary file is created (mypic.jpg~RF1266b4fa.TMP). So far so good. But now, Windows tries to rename mypic.jpg (the original one) to mypic.jpg~RF1266b4fa.TMP. But mypic.jpg~RF1266b4fa.TMP already exists. It has just been created without content. Here my program throws a "already exists" exception.

Is this a normal behaviour? Programms creating a new empty file and later a existing file is renamed to that blank files name? Or is this a unnormal behaviour of the windows image viewer?
Posted: 10/25/2013 04:25:39
by Volodymyr Zinin (EldoS Corp.)

Please check whether the problem is reproducible with the Mapper sample. If it isn't then perform the same behavior in your application.
Also you can use Process Monitor from sysinternals.com to see what I/O requests are sent to file system. Set there to filter only operations sent to your virtual disk (by adding the filter rule "Path"->"begins with"->"X:", where "X:" is a drive letter for your disk) and reproduce the problem.
Posted: 10/25/2013 04:33:24
by Andreas Pross (Standard support level)
Joined: 10/17/2013
Posts: 8

Thanks for that hint.

Mapper sample deletes existing files during rename. It looks like I should do this too.
Posted: 10/29/2013 16:26:55
by Theodor Kleynhans (Standard support level)
Joined: 10/29/2013
Posts: 15

I have seen similar behaviour in other apps, and I suspect it is due to the apps using MoveFileEx() with the MOVEFILE_REPLACE_EXISTING flag and expecting the move to work.
Unfortunately the CBFS API does not currently provide the value of the flag as far as I'm aware. If it did, the callback could allow renames when MOVEFILE_REPLACE_EXISTING is specified but fail it otherwise.
Posted: 10/30/2013 01:54:30
by Volodymyr Zinin (EldoS Corp.)

Windows in its "rename" request passed to file system (to be strict it's IRP_MJ_SET_INFORMATION with the FileRenameInformation flag) specifies the ReplaceIfExists flag. And based on this flag the file system must rename/move the file or fail the request. But in order to simplify the OnRenameFile callback this flag is processed by CBFS itself. So implementation of this callback should always perform to rename/move file.
Posted: 01/10/2014 23:33:02
by Richard Hauer (Basic support level)
Joined: 12/05/2013
Posts: 26

@Vladimir Are you saying that in this case CBFS first issues a delete, and then the rename?
Posted: 01/13/2014 01:13:04
by Volodymyr Zinin (EldoS Corp.)

No. The OnDelete callback isn't called in this case.
When the OnRenameFile callback comes your code needs to rename/move the requested file/directory (or to return an error).
Posted: 01/13/2014 01:18:12
by Richard Hauer (Basic support level)
Joined: 12/05/2013
Posts: 26

Which is to say, rename/move and overwrite if the file exists in all cases?
Posted: 01/13/2014 01:34:48
by Volodymyr Zinin (EldoS Corp.)

Posted: 02/19/2014 07:07:27
by Theodor Kleynhans (Standard support level)
Joined: 10/29/2013
Posts: 15

In my opinion the OnRenameFile callback should get an additional ReplaceIfExists parameter (similar to how CallbackFilter 3 got it recently).
Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages



Topic viewed 4354 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!