how to deal with (A Document being saved by MyApp) files?
Asked Answered
B

2

8

My application uses iCloud. My application stores all its data in 1 document and there should never be more than this 1 document. However, sometimes my NSMetadataQuery returns 2 documents:

0: Documents/(A Document being saved bt MyApp)/MyDoc.ext
1: Documents/MyDoc.ext

This happens mostly when the user opens the app shortly after the iOS device was rebooted.

When inspecting these 2 docs, it is document 0 that is the one with the most recent updates, so this is the one we want.

What is the reason of this "A Document Being Saved" ending up there and being the most recent one and how do I deal with this correctly, so Documents/MyDoc.ext will be the one that has the most recent content.

Thanks, -r

Breannabreanne answered 30/1, 2013 at 16:17 Comment(2)
I have typically seen "(A Document Being Saved By <App>)" when the app crashes while the app is saving. Atomic writing involves writing to a separate file before replacing the existing document -- this appears to be what this directory represents. For this reason, I suspect there is no guarantee that the data in this 'being saved' document is whole and intact, but I am also interested to see if anybody has any experience salvaging them.Thermometry
atomic writes imply no salvagingEarleneearley
L
7

I think Stuart's comment provides most of the answer you'll get. The fact alone that the document is called "(A Document Being Saved by )" and not "(A Document Saved by ) strongly suggests he's right.
I guess it's now up to you to figure out why saving the document crashes or never finishes or gets terminated or whatever. It could be a timeout, if your app takes too long saving the document when going to the background, a crash, or something else - I don't think you've provided enough information for anyone to give you a really precise answer.

Louanneloucks answered 10/6, 2013 at 11:54 Comment(2)
saving seems to work fine here but i get a bunch of empty "(A document being saved by <myapp>)" dirs (on simulator)Gerardgerardo
I do have same issue, Any solution? anyoneStringendo
B
2

The folder called "A Document Being Saved by AppName" inside Documents is a temporary which is used to store for the Binary large object (BLOB).

Normally, if your application is saved successfully, the folder should be emptied. However, if it crash during the save, the folder will be stored some data to let you handle it. Basically, I always remove the directories on the startup time. So, if the BLOB doesn't move into the hidden BLOB directory, it will be not in the Database.

Hope that helps.

Boylston answered 10/6, 2013 at 16:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.