EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Rename erroneously returning ERROR_ALREADY_EXISTS

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
#32808
Posted: 03/27/2015 14:02:35
by david bennett (Standard support level)
Joined: 03/29/2013
Posts: 50

I am using CbFs version 3.

See the code snippet here which is trying to rename a file to a new name, but also wants to make sure that the new name doesn't already exist.

Code
   CString newname = oldname + ext;
   for (int i = 2; PathFileExists(newname); i++)
      newname.Format(L"%s (%d)%s", oldname, i, ext);
   if (::MoveFile(oldname, newname))
      DWORD err = GetLastError();


The above code fails most of the time as the rename gets ERROR_ALREADY_EXISTS. Both the old and new filenames point to my Callback File System. I have set a breakpoint in my OnRenameOrMoveFile() callback. In the cases where the code works, I get a callback. In the cases where it doesn't work, I never get the callback.

The first time I run this after I restart my CbFs, it seems to work every time. If I then rename the file back to the oldname and rerun it, it fails just about every time, but if I reset it and then wait a while (don't know exactly how long), it will succeed. As I noted, in the cases where it succeeds, I get my breakpoint in my OnRenameOrMoveFile() file function. In the cases where it fails, I don't. I have attached a screen shot of Process Monitor (from SysInternals) showing the failing call, though it's not much use because it just fails.

There seems to be some caching going on but have disabled the metadata cache. I am at a loss about what to do at this point. I can probably work around it for this particular example, but it seems to be potentially a much more pernicious problem.


#32809
Posted: 03/27/2015 14:12:10
by Eugene Mayevski (EldoS Corp.)

Thank you for the report.

Before we dig deeper into the problem it would be nice to determine the desired outcome. You are using version 3, which is quite old (we are working on version 6 now) and can not be updated anyway. So the most obvious advice would be to consider upgrading to version 5.

What you can do in your situation is review your implementations for OnGetFileInfo and OnEnumerateDirectory event handlers. When the file operation is performed, either OnGetFileInfo or OnEnumerateDirectory is triggered (the latter can be triggered with the filename instead of the mask). Please check that these events are handled and return proper information for the files in question.


Sincerely yours
Eugene Mayevski
#32811
Posted: 03/27/2015 14:42:49
by david bennett (Standard support level)
Joined: 03/29/2013
Posts: 50

As you can see from the Process Monitor output that I attached to the original email, the only call to GetFileInformation() is querying the old filename, not the new one and there is no directory call. I will set breakpoints in my code but I think the Process Monitor output is likely to be accurate.

On the version, I was confused. We are using version CbFs 4. We are using Callback Filter version 3.
#32812
Posted: 03/27/2015 14:51:34
by david bennett (Standard support level)
Joined: 03/29/2013
Posts: 50

You are correct! It's my problem. Sorry to bother you!
#32813
Posted: 03/27/2015 14:53:58
by Eugene Mayevski (EldoS Corp.)

Great, thank you for letting us know the outcome.

As for the procmon log - I have read the original message via e-mail and the link to the attachment was not present there, so I've overlooked the log. I can see the link via the web page.


Sincerely yours
Eugene Mayevski
#32815
Posted: 03/27/2015 16:09:43
by david bennett (Standard support level)
Joined: 03/29/2013
Posts: 50

FWIW, your forum submittal page has what I would consider a bug. I attached the .png file when I was entering the original issue. I then hit "preview" and then after the preview was okay I submitted the question. Apparently the "preview" option lost the image that I attached. I noticed that and went to edit the submission and when through the same steps (i.e. I previewed it) and when I sumbitted again the image was again lost. I had to *not* do a preview in order for it to keep the image attached. I'm using Internet Explorer and maybe if I were using a different browser it would behave differently.

The lesson is not to use preview, I guess.
#32816
Posted: 03/28/2015 02:22:12
by Eugene Mayevski (EldoS Corp.)

Thank you, we will review the issue with the attachments.


Sincerely yours
Eugene Mayevski
Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.

Reply

Statistics

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