Hi Raphael,

[EMAIL PROTECTED] (Raphael Manfredi) wrote:

> :> * Added string evaluation code, that can evaluate ~/foo and
> :>  $HOME or ${HOME}.

Your code evaluates these variables for *any* string property,
although string properties are used for much more than paths, 
CMIIW. This might not be critical at the moment but depending on
what string properties are used for in the future this might cause
one or another nasty bug. I somewhat wonder whether this complexity is
really necessary here. 
 
> :I would have prefered to handle "" as a special case...KISS.

Consider the following code sketch:

char *getdownloaddir() {
        char *path = getproperty(PROP_DIR_DOWNLOAD);
        return_if_fail(NULL != path);

        if ('\0' == *path) {
                int ret;                
                char *homedir = gethomedir();
                return_if_fail(NULL != homedir);

                ret = asprintf(&path, "%s/download", homedir);
                return_if_fail(-1 != ret);
                
                ret = mkdir(path);
                return_if_fail(-1 != ret || errno == EEXIST);

                setproperty(PROP_DIR_DOWNLOAD, path);
        }
        return path;
}

Now, all you have to handle is getdownloaddir() == NULL, but that
shouldn't be a greater problem than fopen() == NULL. And of course
you must not access PROP_DIR_DOWNLOAD (nor the variable) anywhere
else.
 
> Yes.  I thought about that too, but dismissed it as being too hacky.

It doesn't add any interesting feature like your variable evaluation
code but it's simple, safe and transparent.

> Well, at one time I thought of "~/gnutella/tmp" but the problem is
> that if the directory does not exist, we fallback to $HOME anyway,
> in the file_path_changed() callback.

GTKG depends on the presence resp. the possibility to create
$GTK_GNUTELLA_DIR. So depending on another (sub-)directory doesn't
really make anything worse. GTKG also relies on /tmp and will crash
if it doesn't exist. I mean, some things can't or shouldn't be
forcefully fixed. GTKG is a tool for downloading and uploading so
it's quite logic that you need at least one directory to write to
and to read from. If some file cannot be created the user will be
warned so *he* can fix the problem. 
 
-- 
Christian

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to