mkdir exportdir's parent, if necessary
Tux Paint's export features will fail if the parent of the export directory didn't exist. e.g., using the default (either via XDG or hard-coded fallback) of "~/Pictures/TuxPaint/", Tux Paint could not export if "~/Pictures/" didn't exist yet. It will now try to mkdir it as well. h/t Tim Dickson Updated OPTIONS documents to explain this. Also, documenting --exportdir in manpage (was missing!)
This commit is contained in:
parent
c2a4b9862a
commit
c97932606f
9 changed files with 74 additions and 20 deletions
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
get_fname.c
|
||||
|
||||
Copyright (c) 2009 - 2020
|
||||
Copyright (c) 2009 - 2021
|
||||
http://www.tuxpaint.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
|
|
@ -57,6 +57,11 @@
|
|||
and easily-accessible place for end users to retrieve the exports.
|
||||
|
||||
The defaults may be overridden with the "--exportdir" option.
|
||||
|
||||
* DIR_EXPORT_PARENT: The parent of the directory
|
||||
specified by DIR_EXPORT. (e.g., if /home/username/Pictures/TuxPaint/
|
||||
is our export dir., we may need to make .../Pictures first,
|
||||
the first time we export something.)
|
||||
*/
|
||||
|
||||
|
||||
|
|
@ -88,7 +93,7 @@ char *get_fname(const char *const name, int kind)
|
|||
dir = savedir;
|
||||
} else if (kind == DIR_DATA) {
|
||||
dir = datadir;
|
||||
} else if (kind == DIR_EXPORT) {
|
||||
} else if (kind == DIR_EXPORT || kind == DIR_EXPORT_PARENT) {
|
||||
dir = exportdir;
|
||||
}
|
||||
|
||||
|
|
@ -97,6 +102,20 @@ char *get_fname(const char *const name, int kind)
|
|||
dir, (*name) ? '/' : '\0', /* Some mkdir()'s don't like trailing slashes */
|
||||
name);
|
||||
|
||||
if (kind == DIR_EXPORT_PARENT) {
|
||||
int len, i, stop;
|
||||
|
||||
stop = -1;
|
||||
len = strlen(f);
|
||||
for (i = len - 1; i >= 0 && stop == -1; i--) {
|
||||
if (f[i] == '/')
|
||||
stop = i;
|
||||
}
|
||||
if (stop != -1) {
|
||||
f[stop] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return strdup(f);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue