mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 13:14:29 -08:00
create config directory in HOME and read config from there
This commit is contained in:
46
fuse/main.c
46
fuse/main.c
@@ -28,7 +28,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/types.h>
|
#include <sys/stat.h>
|
||||||
#include <bits/fcntl-linux.h>
|
#include <bits/fcntl-linux.h>
|
||||||
#include <fuse/fuse_common.h>
|
#include <fuse/fuse_common.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
@@ -397,23 +397,22 @@ static void parse_config(int *argc, char ***argv, char *configfile)
|
|||||||
// commandline and should be set by the configuration file
|
// commandline and should be set by the configuration file
|
||||||
|
|
||||||
// try set config file first if set
|
// try set config file first if set
|
||||||
if (configfile != NULL && (fp = fopen(configfile, "r")) != NULL) {
|
if (configfile != NULL) {
|
||||||
parse_config_file(fp, argc, argv);
|
if ((fp = fopen(configfile, "r")) != NULL) {
|
||||||
fclose(fp);
|
parse_config_file(fp, argc, argv);
|
||||||
return;
|
fclose(fp);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Cannot open configuration file %s\n", configfile);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// try "./.mediafire-tools.conf" second
|
// then try "~/.mediafire-tools/config"
|
||||||
if ((fp = fopen("./.mediafire-tools.conf", "r")) != NULL) {
|
|
||||||
parse_config_file(fp, argc, argv);
|
|
||||||
fclose(fp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// try "~/.mediafire-tools.conf" third
|
|
||||||
if ((homedir = getenv("HOME")) == NULL) {
|
if ((homedir = getenv("HOME")) == NULL) {
|
||||||
homedir = getpwuid(getuid())->pw_dir;
|
homedir = getpwuid(getuid())->pw_dir;
|
||||||
}
|
}
|
||||||
homedir = strdup_printf("%s/.mediafire-tools.conf", homedir);
|
homedir = strdup_printf("%s/.mediafire-tools/config", homedir);
|
||||||
if ((fp = fopen("./.mediafire-tools.conf", "r")) != NULL) {
|
if ((fp = fopen(homedir, "r")) != NULL) {
|
||||||
parse_config_file(fp, argc, argv);
|
parse_config_file(fp, argc, argv);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
@@ -550,11 +549,30 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int ret,
|
int ret,
|
||||||
i;
|
i;
|
||||||
|
char *homedir;
|
||||||
|
char *cachedir;
|
||||||
|
|
||||||
struct mediafirefs_user_options options = {
|
struct mediafirefs_user_options options = {
|
||||||
NULL, NULL, NULL, NULL, -1, NULL
|
NULL, NULL, NULL, NULL, -1, NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if ((homedir = getenv("HOME")) == NULL) {
|
||||||
|
homedir = getpwuid(getuid())->pw_dir;
|
||||||
|
}
|
||||||
|
homedir = strdup_printf("%s/.mediafire-tools", homedir);
|
||||||
|
/* EEXIST is okay, so only fail if it is something else */
|
||||||
|
if (mkdir(homedir, 0755) != 0 && errno != EEXIST) {
|
||||||
|
perror("mkdir");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
cachedir = strdup_printf("%s/cache", homedir);
|
||||||
|
if (mkdir(cachedir, 0755) != 0 && errno != EEXIST) {
|
||||||
|
perror("mkdir");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
free(cachedir);
|
||||||
|
free(homedir);
|
||||||
|
|
||||||
parse_arguments(&argc, &argv, &options);
|
parse_arguments(&argc, &argv, &options);
|
||||||
|
|
||||||
connect_mf(&options);
|
connect_mf(&options);
|
||||||
|
|||||||
Reference in New Issue
Block a user