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
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Bad groupid (and userid?) on files created in shared folder under latest updates

[ Edited ]

I've just had a problem report regarding an odd issue that is associated with the latest updates.

 

Battery Guru can write export files (in CSV format) to shared/documents/BatteryGuru.  The files are simple text files created with code basically like this:

            stream = new FileStream();
            stream.openAsync(temp_path, FileMode.WRITE);

# later on in an event handler
 stream.writeUTFBytes(...)

# later on in another event handler
stream.close();

The catch is that the files are initially created inside the app's tmp/ folder in the sandbox, and only after they are completely written are they moved to shared/documents/BatteryGuru, with a   "temp_path.moveTo(dest, true);"

Under previous versions this worked fine, and files came out looking like this (as seen by "ls -l" via SSH):

-rwxrw----   1 nobody    1000_shared   3020833 Nov 11 20:25 export-20110720T142136-20110909T235450.csv

These files were visible from the MEDIA network share and could be copied off the PlayBook.  They could also be moved around, renamed, etc, just like any other file created in the shared/ folders in the first place.

 

Under the latest updates, 1.0.8.4985 and 2.0.0.4869, things have changed.  Here's what "ls -l" sees on the 1.0.8 unit:

-rw-rw----   1 100441000 10044        969073 Nov 27 20:21 export-20111110T183253-20111127T202119.csv

On my 2.0.0.4869 unit, here's a similar case:

-rw-rw----   1 100591000 10059        326405 Nov 27 21:57 export-20111123T185137-20111127T215640.csv

The problem is that these files cannot be read from the MEDIA share, nor in fact are even listed in a directory listing when viewed from there. They cannot be copied, they cannot be opened, except perhaps by the app that wrote them. (I can't check that yet since Battery Guru does not read back its own export files.. I'd have to make a test build to check that.)

 

When another AIR app (e.g. Files & Folders) attempts to read the file, it reports a 3001 error which means this "File or directory access denied."

 

When I try it from SSH, I get this:

$ cp export-20111110T183253-20111127T202119.csv ../tempfile
cp: Can't open source file.  (export-20111110T183253-20111127T202119.csv): Permission denied

 

I'm not actually sure the problem is related to my initially writing to tmp/ though.  The BatteryGuru/ folder itself is created automatically if it doesn't exist.  On my 1.0.8 unit the folder already existed from before, so it looks like this:

drwxrws---   2 nobody    1000_shared      4096 Nov 27 20:21 BatteryGuru

Under 2.0, where I just did an export for the first time, the new BatteryGuru folder looks like this:

drwxrws---   2 100591000 1000_shared      4096 Nov 27 21:57 BatteryGuru

I can see that other apps may be affected in a similar fashion, though the basic inability to read the files at all may not be affecting them for some reason... maybe because they aren't writing to a subfolder?  Here are two files, one written by the Box.net app, the other by the "native" DocumentsToGo app, for the updated OS, and the earlier one:

# newly written since update to 1.0.8.4985:
-rw-rw-r--   1 100491000 1000_shared   2016327 Nov 10 21:17 AT32UC3C Series Summary.pdf
-rw-rw-r--   1 100121000 1000_shared     19968 Nov 16 18:56 BBX Python Todos.doc

# written by 1.0.7:
-rwxrw----   1 nobody    1000_shared    111705 Nov 11 20:24 GUGO.pdf
-rwxrw----   1 nobody    1000_shared     12288 Nov 11 20:24 Todo items.doc

 

Anyone else experiencing an actual problem reading files written by their app to the shared folders?

 

In particular, could anyone whose app writes to its own subfolder, created in the shared/ folder tree, please check and see whether under the updated OS version(s) they have any issue like mine, where the file is inaccessible though shows in a local directory listing but is invisible when viewed via Samba?


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!
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Bad groupid (and userid?) on files created in shared folder under latest updates

I've filed this prospectively as https://www.blackberry.com/jira/browse/TABLET-373 just in case it's an OS problem and not directly my fault, as it may be considered a critical bug needing an urgent fix.

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!
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
My Carrier: Vodafone

Re: Bad groupid (and userid?) on files created in shared folder under latest updates


peter9477 wrote:

Anyone else experiencing an actual problem reading files written by their app to the shared folders?

 

In particular, could anyone whose app writes to its own subfolder, created in the shared/ folder tree, please check and see whether under the updated OS version(s) they have any issue like mine, where the file is inaccessible though shows in a local directory listing but is invisible when viewed via Samba?


Files & Folders creates /accounts/1000/shared/downloads/Dropbox and writes there when you use the "Download and open" function. You can also do it manually of course. No problems reading that back or accessing it via Wifi with 2.0.0.4869. Also no problem accessing pre-existing folders after an upgrade from 1.07 to 2.0.

 

Difference is that F&F writes directly to the folder, it doesn't write to ./tmp first and then move the file, as you describe...

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.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Bad groupid (and userid?) on files created in shared folder under latest updates

Thanks Jon. I've just confirmed that files/folders created in tmp/ have ownership as shown, instead of the 1000_shared group owner. Moving them out from tmp/ doesn't affect the permissions or ownership, so that's where this is coming from.

I suppose it may not be quite as serious as I thought before, aside from the complications for any other apps (if there are any) which took my approach.

Looks like a workaround will have to be to create the files initially as "hidden" ones, with a leading dot.. not that this actually does much for us since so few things seem to respect that right now.

My use case with this copy-from-tmp thing was to prevent the user accidentally accessing a partially-written export file. The file can take minutes to generate, if there's enough data... It seemed building it "in private" like that would be a good thing, and then the atomic rename at the end makes it instantly appear.

Fortunately the user can still delete those files since the BatteryGuru folder permissions and ownership allow it.

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!
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Bad groupid (and userid?) on files created in shared folder under latest updates

I've found what looks like it may be a viable workaround, though it's imperfect.

 

My app can initially create a fresh folder in shared/documents.  That gives the folder set-group-id (the "s" bit in the permission field) and a group of 1000_shared.

 

The folder is then moved to the tmp/ folder in the sandbox as, say, tmp/magicfolder.

 

The export file is generated into the tmp/magicfolder location, where because of the set-group-id bit it magically acquires group 1000_shared instead of the app's own group.

 

The export file is renamed to appear under the shared/documents/BatteryGuru location.

 

The only difference between this and what it looks like if you create the file initially in that location is that it has "world" read and write permissions. Normally the files have only rw-rw---- but this one has rw-rw-rw-.  Doesn't seem like it would be a concern.


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!
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
My Carrier: Vodafone

Re: Bad groupid (and userid?) on files created in shared folder under latest updates


peter9477 wrote:
My use case with this copy-from-tmp thing was to prevent the user accidentally accessing a partially-written export file. 

Perfectly valid use case IMO. Could you use an ANE to adjust the privs before moving the file...?

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.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Bad groupid (and userid?) on files created in shared folder under latest updates

With native code we could change the permissions on any file we own, but we can't change the group ownership.

That would mean we could do a o+r on the file, allowing anyone to read it (even over Samba), though it's not quite the same outcome.

It's a second option for a workaround anyway, but a lot more work than my trick above, unless you've already got the whole ANE thing completely nailed and integrated with your tools etc.

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!
Please use plain text.