maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Location for storing data: /home/user/appname? (https://talk.maemo.org/showthread.php?t=27021)

darethehair 2009-02-21 02:53

Location for storing data: /home/user/appname?
 
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 :(

ace 2009-02-21 04:14

Re: Location for storing data: /home/user/appname?
 
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".

yerga 2009-02-21 11:39

Re: Location for storing data: /home/user/appname?
 
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 ;)

darethehair 2009-02-21 14:01

Re: Location for storing data: /home/user/appname?
 
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.

stale 2009-02-21 15:17

Re: Location for storing data: /home/user/appname?
 
Quote:

Originally Posted by darethehair (Post 266061)
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.

lardman 2009-02-21 17:42

Re: Location for storing data: /home/user/appname?
 
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 2009-02-21 19:16

Re: Location for storing data: /home/user/appname?
 
Quote:

Originally Posted by yerga (Post 266041)
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?

BrentDC 2009-02-21 19:26

Re: Location for storing data: /home/user/appname?
 
Quote:

Originally Posted by darethehair (Post 266123)
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.

darethehair 2009-02-21 19:39

Re: Location for storing data: /home/user/appname?
 
Quote:

Originally Posted by BrentDC (Post 266125)
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')



All times are GMT. The time now is 14:09.

vBulletin® Version 3.8.8