Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

BB10 Files Changed to Readonly

Has anyone experienced their files in the shared area being changed to read-only after the app has created them?  I have a DB file that after the app has created them, at some point, they become read-only and can no longer be editted.  I believe this occurs with a backup, but I need to do more testing to verify.  The read-only status is by looking at the file browser, properties of the file.

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: BB10 Files Changed to Readonly

Update. It seems that SQLLite files get changed to read-only when opened, but they are not being set back when the DB file is closed. Then the next time, it is opened, the SQLLite API will crash your app.

I wrote a little ANE to change the file permissions, but it seem to hate that as well. Might be changeing the perms too much. Will need to play around with this.

This does not seem to be an issue on the PlayBook.
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: BB10 Files Changed to Readonly

More data...
Seems not to impact DB files in the app-storage directory, just those in the shared/documents directory.
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: BB10 Files Changed to Readonly

Saga continues:

Looks like setting the file to 644 prior to opening the DB file resolves the problem.  I need to test some more in a production app, but the mini-test seems to avoid the DB file from crashing the app.

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: BB10 Files Changed to Readonly

Well, that failed on the actual device. Back to square one.
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: BB10 Files Changed to Readonly

[ Edited ]

Got it all working.  Solution:

1) Keep SQLLite DB files in app-storage.  documents directory changes the file perms to read-only and the DB will not open to write to the next go around (this only seems to be a BB10 issue.  PlayBook has been working fine for over a year).

2) Provided import and export feature for needed DB files

3) When importing, you have to copy the data, not the file.  If you copy the file, the read-only perms remain.  So you have to load the data (URLLoader, binary data) and write the data into the file in app-storage.

 

The apps have not crashed since, so hopefully this resolves things.

 

////////////////////////////////////////////////////////////////////////////////
        public static function copyFileDataTo( from : File, to : File, remove_from : Boolean = false ) : void
        {
            var loader : URLLoader = new URLLoader();
            loader.dataFormat = URLLoaderDataFormat.BINARY;
            loader.addEventListener( Event.COMPLETE, FileLoaded );
            loader.addEventListener( IOErrorEvent.IO_ERROR, FileError );
            loader.load( new URLRequest( 'file://' + from.nativePath ) );
            
            function FileLoaded( event : Event ) : void
            {
                loader.removeEventListener(Event.COMPLETE, FileLoaded );
                loader.removeEventListener(IOErrorEvent.IO_ERROR, FileError);
                
                var stream :FileStream = new FileStream();
                stream.open( to, FileMode.WRITE );
                stream.writeBytes( loader.data, 0, loader.bytesTotal );
                stream.close();
                //trace( 'file copied ' + to.name );
                
                if( remove_from )
		{
			setTimeout( from.deleteFile, 100 );
		}
		to.dispatchEvent( new Event( Event.COMPLETE ) );
            }
            
            function FileError( event : Event ) : void
            {
                loader.removeEventListener(Event.COMPLETE, FileLoaded );
                loader.removeEventListener(IOErrorEvent.IO_ERROR, FileError);
                trace( 'ExtendedFile::copyFileDataTo error' );
		to.dispatchEvent( new IOErrorEvent( IOErrorEvent.IO_ERROR ) );
            }
        }

 

Please use plain text.
Developer
UberschallSamsara
Posts: 1,029
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

Re: BB10 Files Changed to Readonly

Thanks for the blow-by-blow and resolution.

 

Gonna file a JIRA for this?  Does BlackBerry assert that it's supposed to work this way for some reason?

If it's working rationally on PlayBook and PB apps depend on that, those apps could break when BB10 and such apps get ported to PB.

 

Any DB size gotchas for FileStream?

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: BB10 Files Changed to Readonly

Dont know about size limitation. Probably limited to memory. I will have to create a demo app to reproduce it for JIRA. I have a couple of email out to see if it is an issue.
Please use plain text.
Developer
Innovatology
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course

Re: BB10 Files Changed to Readonly

I *think* I remember seeing something similar while playing around on the PlayBook before, though it was probably in the beta 2.0. If I remember correctly, creating a .db file in a shared folder wouldn't work. You needed to create it in the sandbox, then move it to the shared folder...

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Please use plain text.