Active Topics

 


Reply
Thread Tools
darethehair's Avatar
Posts: 273 | Thanked: 104 times | Joined on Mar 2007 @ Manitoba, Canada
#1
OK, I feel a bit silly for not realizing this a *lot* earlier during development of my latest app -- but it occurs to me that the reason that it has so much trouble doing a file 'save' is that the 'user' account has very little 'write' access -- except (mostly) to '/home/user'.

I had intended to allow the user to save to the directory containing my actual app (i.e. /usr/lib/appname) -- but my program (and any others that attempt to do the same thing?) silently fail when a 'save' is attempted to a directory like that -- presumably since only 'root' has write access to most of the file system.

So...is the 'official' spot for apps to save data supposed to be '/home/user'? Or, to keep data separate, '/home/user/appname'? I suppose that the user then has the ability to make this a logical link to, say, one of the '/media' (card) locations? If so, then there is not much point is writing an app that lets the person navigate all over the file system for files to read/write -- and should instead 'hardcode' this to '/home/user/appname'?

Thanks for any feedback! My silly app is stalled out due to this issue
__________________
There is nothing more dangerous than a bored cat.
 
ace's Avatar
Posts: 296 | Thanked: 80 times | Joined on Dec 2007
#2
I think "/home/username/.appname" is common for user-specific app settings and files on Linux systems. Note the period. It makes it a hidden folder, so it won't take up space in regular directory listings.

Also, when/if your app requires a lot of storage space, I think it's a good idea to let/require the user to pick a place to store the files. But I'd probably still keep small setting files under "/home/username/.appname".
__________________
[SIGPIC][/SIGPIC]
 

The Following User Says Thank You to ace For This Useful Post:
yerga's Avatar
Posts: 696 | Thanked: 1,012 times | Joined on Mar 2006 @ Asturies, Spain
#3
I would add that isn't a good idea hardcode the "/home/user" path, because while Maemo only has "user", for example in Mer you create the username with the name you want. So, for compability with Mer is a good idea detect the user who is using the application.

Example code in python:
Code:
import os
os.path.expanduser("~")
Some of my apps have hardcoded this path, but I am fixing it ASAP
__________________
Daniel Martín Yerga
maemo.org profile
Twitter
 

The Following User Says Thank You to yerga For This Useful Post:
darethehair's Avatar
Posts: 273 | Thanked: 104 times | Joined on Mar 2007 @ Manitoba, Canada
#4
Thanks to both of you (and future others) responding to my query

It occurred to me that when I wrote 'Mephemeris', that I made sure that '/usr/lib/mephemeris' had done a 'chmod 777' on the directory, to insure that the 'user' had full access to write files there (for the downloaded image pics, which overwrote each other so as not to accumulate).

I guess I am still wondering if this is 'wrong' in the Maemo world or not? Perhaps it is 'common' in the Linux world to write to '/home/user/.appname', but I notice that on *my* N800, there is almost nothing there at all.

As well, in Python, I am wondering what the heck advantage there is to using the 'hildon.FileChooserDialog' instead of the normal 'gtk.FileChooserDialog'. For example, so far I have not found evidence that it looks nicer, or obeys 'filtering' rules that I give it, and also (I think) ignoring my 'set_current_directory' command -- so why is it so strongly encouraged? This all plays into my question of providing the user with a good GUI for finding/writing files on Maemo.
__________________
There is nothing more dangerous than a bored cat.

Last edited by darethehair; 2009-02-21 at 14:06.
 
Posts: 39 | Thanked: 13 times | Joined on Apr 2008 @ Genoa, Italy
#5
Originally Posted by darethehair View Post
It occurred to me that when I wrote 'Mephemeris', that I made sure that '/usr/lib/mephemeris' had done a 'chmod 777' on the directory, to insure that the 'user' had full access to write files there (for the downloaded image pics, which overwrote each other so as not to accumulate).

I guess I am still wondering if this is 'wrong' in the Maemo world or not?
For temporary files /tmp should be used (you should evaluate if they will fit since in Maemo /tmp file system is not so big).
Keep in mind that content of /tmp will be lost after a reboot.

See also http://tldp.org/LDP/Linux-Filesystem...tml/index.html
I don't know how much this is applicable in Maemo.

Last edited by stale; 2009-02-21 at 15:31.
 
Posts: 2,102 | Thanked: 1,309 times | Joined on Sep 2006
#6
Changing anything under /usr to be writeable by a mere user is "wrong"

As explained above, temporary files should go in /tmp and any user files should go somewhere under the user's home directory (~/)
 
darethehair's Avatar
Posts: 273 | Thanked: 104 times | Joined on Mar 2007 @ Manitoba, Canada
#7
Originally Posted by yerga View Post
Code:
import os
os.path.expanduser("~")
Yerga, this is definitely a good tip, but how can one 'anticipate' which user will be running the app, so that the app install can pre-create the app subdirectory in '/home/xxxusername/.appname'?

Or do you intend to also change your app to 'create' the necessary '.appname' subdirectory if it doesn't exist?
__________________
There is nothing more dangerous than a bored cat.
 
BrentDC's Avatar
Posts: 903 | Thanked: 632 times | Joined on Apr 2008
#8
Originally Posted by darethehair View Post
Yerga, this is definitely a good tip, but how can one 'anticipate' which user will be running the app, so that the app install can pre-create the app subdirectory in '/home/xxxusername/.appname'?

Or do you intend to also change your app to 'create' the necessary '.appname' subdirectory if it doesn't exist?
I don't know how yerga does it, but I think it's a good practice to test to see if /home/$USER/.appname/ exists at runtime. I usually use this statement to test:

Code:
if not os.path.exists(path_here):
    <statements here>
Then if your application's home directory folder is deleted, your application won't just "break"

That may not be the best way, but it works.
 

The Following User Says Thank You to BrentDC For This Useful Post:
darethehair's Avatar
Posts: 273 | Thanked: 104 times | Joined on Mar 2007 @ Manitoba, Canada
#9
Originally Posted by BrentDC View Post
Code:
if not os.path.exists(path_here):
    <statements here>
Cool idea! For me:

Code:
if not os.path.exists("~/.appname"):
          os.system('mkdir -p ~/.appname')
__________________
There is nothing more dangerous than a bored cat.
 
Reply


 
Forum Jump


All times are GMT. The time now is 08:12.