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
BlackBerry Development Advisor
elena_laskavaia
Posts: 417
Registered: ‎10-27-2010
My Device: PlayBook

Application sandbox file system layout

Here is an overview of application sandbox files system layout for the latest release 0.9.2 

(disclaimer: can change in final version but unlikely)

 

Applications will be run in the directory we call "sandbox". Name of this directory is irrelevant and cannot be relied on.

Application should not attempt to access any files outside of this directory. Sandbox is the default "working directory".

The structure is

 

  •   app
  •   data
  •   tmp
  •   logs
  •   shared

 

All except shared are app's private directories, only the app can read/write files there.

 

The "app" directory is the link to where application files are installed (what was packaged in the bar file), these files are read only. For air application files will be in subdirectory "air" (i.e. app/air/your_file).

 

The private data directory is "data". Application has full access to this directory (read/write). The $HOME env var is set to this directory. To initiate the sandbox app may copy files from "app" to "data" (for example user modifiable config files) on the first run.

 

The "tmp" directory can be used to create temporary files, application should take care of cleaning these files, but system may remove them at any time app is not running - so it cannot be used to persist data, only "data" directory should be used for this.

 

The "logs" is used for development, application stdin and stdout is redirected to logs/log file, as well as "core" files will be created there if app crashes.

 

The "shared" is link to common location where all apps share files. It has the following structure:

 

  • music 
  • videos 
  • documents 
  • clipboard 
  • bookmarks 
  • books 
  • misc 
  • voice

If you know how all of  it maps to air File class fields please post here too

 

Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: Application sandbox file system layout

Haven't figured out 100% what to do with this info. So, in one of my apps I export an image. Currently I export it to File.userDirectory. Should I change this to the shared folder? And how?

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
shawnblais
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: Application sandbox file system layout

[ Edited ]

 File.userDirectory is the convention for saving app settings on Android, can we still rely on that?

It would be nice to not have to write Playbook specific code here, can we just make userDirectory point to /data?

Developer
Harry_Dodgson
Posts: 153
Registered: ‎10-26-2010
My Device: Bold 9900

Re: Application sandbox file system layout

[ Edited ]

Hi,

 

The directory tree maps (as elena listed) start at     File.applicationStorageDirectory.nativePath

which is currently     /accounts/1000/appdata/<actual_dname>

There are a couple folders there that weren't listed.

 

I can see the .../shared/ tree, but haven't managed to write anything down that path successfully yet.

 

Harry

--------------
Accepted PlayBook Applications: Marmi-doos, BASIC, Run and Hide, SuperClip
Accepted OS4-7 SmartPhone App: KeepLightOn
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Application sandbox file system layout

Here's the mapping:

 

AliasPath
File.applicationDirectory (appname)/app/air
File.applicationStorageDirectory (appname)/data
File.desktopDirectory (appname)/
File.documentsDirectory (appname)/shared/documents
File.userDirectory (appname)/shared/documents

 

In each case, in the above, (appname) is really "/accounts/1000/appdata/FooBar.RmlsASDFadfdsldskdCagAciadCA" or whatever, where the last part is the now-familiar Package Name combined with the Package Id.

 

So it looks like we don't even have to try to choose between user or documents directory, as they point (for now) to the same place.  I'd ignore "desktop" and quite possibly it's read-only anyway.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Harry_Dodgson
Posts: 153
Registered: ‎10-26-2010
My Device: Bold 9900

Re: Application sandbox file system layout

Hi,

 

    Thanks Peter.  I wrote a bunch of pictures into the documentsDirectory and can see them using browse() from my already submitted app.

 

Harry

 

--------------
Accepted PlayBook Applications: Marmi-doos, BASIC, Run and Hide, SuperClip
Accepted OS4-7 SmartPhone App: KeepLightOn
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: Application sandbox file system layout

And what if my app generates an image for the enduser so he can use it? For example as an attachment in a mail, post on twitter, transfer to pc... Where should I save it then?

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
Harry_Dodgson
Posts: 153
Registered: ‎10-26-2010
My Device: Bold 9900

Re: Application sandbox file system layout


zezke wrote:

And what if my app generates an image for the enduser so he can use it? For example as an attachment in a mail, post on twitter, transfer to pc... Where should I save it then?


File.documentsDirectory will work as it is shared between apps.  I used one app to write the pictures into it, and my game app to view/select/add them as backdrops.

--------------
Accepted PlayBook Applications: Marmi-doos, BASIC, Run and Hide, SuperClip
Accepted OS4-7 SmartPhone App: KeepLightOn
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: Application sandbox file system layout

Thank you for that clarification.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Application sandbox file system layout

@zezke, if you didn't mind some PB-specific code, you could write to "photos/" under the documentsDirectory. 

 

That was the only folder Elena missed in her list above.

 

It looks like our options are pretty simple at the moment actually:

 

  1. files written to only by the application, for use within that application, go to File.applicationStorageDirectory
  2. files for unrestricted use by the user, and certainly if to be used with other apps, go in documentsDirectory or userDirectory, but there's currently no distinction between them so pick whichever feels best to you. I'd use the latter, since it seems to me that with documents/  (listed above) as a subdir of the main shared directory, that's where documentsDirectory ought to point.
  3. if you don't mind some PB-specific support, consider adding one of the listed subfolders below the userDirectory, with things like File.userDirectory.resolvePath('photos/myimage.jpg').

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!