Skip navigation.
 
mlRe: -saveDocument: and package problems
FROM : James Hober
DATE : Tue Feb 19 19:30:15 2008

I don't know why your users are losing data but I do know that in 
deep sleep, NSTimers do not fire (I think because NSRunLoops stop.)

You will likely want to do something on wake from deep sleep.  To do 
that:

    //set up notification for awake from sleep
    [[[NSWorkspace sharedWorkspace] notificationCenter] 
addObserver:self
                                                           
selector:@selector(didAwakeFromSleep)
                                                               
name:NSWorkspaceDidWakeNotification
                                                             
object:nil];

- (void)didAwakeFromSleep
{
    //delay so that there's time to re-establish internet connection 
after wake if that is needed
    [self performSelector:@selector(doSomeKindOfUpdate)
                withObject:nil
                afterDelay:DELAY_AFTER_WAKE_FROM_SLEEP];
}

James


On Feb 19, 2008, at 9:37 AM, Keith Blount wrote:

> Message: 11
> Date: Tue, 19 Feb 2008 09:28:00 -0800 (PST)
> From: Keith Blount <<email_removed>>
> Subject: -saveDocument: and pamailto:<email_removed> 
> problems
> To: <email_removed>
> Message-ID: <296747.42019.<email_removed>>
> Content-Type: text/plain; charset=us-ascii
>
> Hi,
>
> I've had a couple of reports of serious data loss in my app and am 
> stumped. I'm wondering if anyone here might have any ideas; perhaps 
> I have made a bad assumption somewhere.
>
> My app uses a package format to save its data - a regular folder 
> (but with an extension and icon, obviously) containing a bunch of 
> RTFD files (the text documents that can be opened by my app) and a 
> saved dictionary file containing a structured list of these files 
> for the source list.
>
> I open the package using NSDocument's - readFromURL:ofType:error:. 
> In this method I just look for the dictionary file and get 
> information from that, and load into the editor the text file that 
> was last opened (well, this is vastly simplified, but this is the 
> main gist).
>
> To save the package, I've overridden NSDocument's -saveDocument:. 
> It doesn't call super's method at all - all it does is write any 
> text files that have been marked as changed into the project 
> package as RTFD files and saves the project dictionary file.
>
> In the past month, I've had two different users report a data loss 
> issue to me. In both cases, it seems that their computer has gone 
> into a deep sleep with my app open. Upon coming out of sleep - I'm 
> not sure at which point here as the users have been vague, but I 
> would imagine after they have closed and reopened the project - 
> everything inside the package has been wiped except for the RTFD 
> file that corresponds with the text document that is open in the 
> text view. I'm not sure if the deep sleep has anything to do with 
> it or is just a coincidence.
>
> I should add that my app auto-saves on a delayed timer, so that -
> saveDocument: gets called after a few seconds of inactivity (any 
> key-press or mouse movement delays the save until two seconds of 
> inactivity have passed), but I don't think that has any effect here.
>
> I've checked all my calls to NSFileManager's -
> removeFileAtPath:handler: and various calls to -writeToFile:... to 
> see if anything could be accidentally replacing the project 
> directory and there is nothing in my code that could be explicitly 
> wiping these files; in the affected projects, there are files that 
> get wiped that are never even touched after the initial project 
> creation (for instance, the file version info file).
>
> Is there anything in the system that I have described that would be 
> leaving my app open to such data loss? The app has thousands of 
> users and this has only ever been reported by two or three users, 
> but when it comes to data loss I don't want to assume that it is 
> just a fault with their machines or something odd that they have 
> done. Both recent users have swore that they have done nothing odd 
> to the file - they haven't moved it, synchronised it or anything else.
>
> If anyone has any ideas about what might cause this sort of thing, 
> I'd be very grateful to hear them. I know the above isn't much to 
> go on, but there really is nothing else at play in my app that 
> could wipe data.
>
> Many thanks in advance and all the best,
> Keith

Related mailsAuthorDate
ml-saveDocument: and package problems Keith Blount Feb 19, 18:28
mlRe: -saveDocument: and package problems James Hober Feb 19, 19:30
mlRe: -saveDocument: and package problems Keith Blount Feb 19, 20:28
mlRe: -saveDocument: and package problems Benjamin Stiglitz Feb 20, 16:30
mlRe: -saveDocument: and package problems Keith Blount Feb 20, 18:58