}
snprintf(outfile, sizeof(outfile), "%s/backup", root);
- if (makedirs(outfile, 0700, -1, -1))
+ if (makedirs("config", outfile, 0700, 1, -1, -1))
goto fatal;
if (chdir(root)) {
tvherror("config", "unable to find directory '%s'", root);
/* Ensure directory exists */
if (stat(path, &st)) {
config_newcfg = 1;
- if (makedirs(path, 0700, gid, uid)) {
+ if (makedirs("config", path, 0700, 1, gid, uid)) {
tvhwarn("START", "failed to create settings directory %s,"
" settings will not be saved", path);
return;
dirsep = path + l;
}
htsstr_unescape_to(path, filename, sizeof(filename));
- if (makedirs(filename, cfg->dvr_muxcnf.m_directory_permissions, -1, -1) != 0)
+ if (makedirs("dvr", filename,
+ cfg->dvr_muxcnf.m_directory_permissions, 0, -1, -1) != 0)
return -1;
max = pathconf(filename, _PC_NAME_MAX);
if (max < 8)
}
x--;
}
- return makedirs(path, 0700, -1, -1);
+ return makedirs("settings", path, 0700, 1, -1, -1);
}
/**
if (timeshift_filemgr_get_root(buf, len))
return 1;
snprintf(buf+strlen(buf), len-strlen(buf), "/%d", index);
- return makedirs(buf, 0700, -1, -1);
+ return makedirs("timeshift", buf, 0700, 0, -1, -1);
}
/*
char *md5sum ( const char *str );
-int makedirs ( const char *path, int mode, gid_t gid, uid_t uid );
+int makedirs ( const char *subsys, const char *path, int mode, int mstrict, gid_t gid, uid_t uid );
int rmtree ( const char *path );
#define tvhwarn(...) tvhlog(LOG_WARNING, ##__VA_ARGS__)
#define tvhnotice(...) tvhlog(LOG_NOTICE, ##__VA_ARGS__)
#define tvherror(...) tvhlog(LOG_ERR, ##__VA_ARGS__)
+#define tvhalert(...) tvhlog(LOG_ALERT, ##__VA_ARGS__)
time_t dispatch_clock_update(struct timespec *ts);
#define FILE_MODE_BITS(x) (x&(S_IRWXU|S_IRWXG|S_IRWXO))
int
-makedirs ( const char *inpath, int mode, gid_t gid, uid_t uid )
+makedirs ( const char *subsys, const char *inpath, int mode,
+ int mstrict, gid_t gid, uid_t uid )
{
int err, ok;
size_t x;
if (!err && gid != -1 && uid != -1)
err = chown(path, uid, gid);
if (!err && !stat(path, &st) &&
- FILE_MODE_BITS(mode) != FILE_MODE_BITS(st.st_mode))
+ FILE_MODE_BITS(mode) != FILE_MODE_BITS(st.st_mode)) {
err = chmod(path, mode); /* override umode */
- tvhtrace("settings", "Creating directory \"%s\" with octal permissions "
- "\"%o\" gid %d uid %d", path, mode, gid, uid);
+ if (!mstrict) {
+ err = 0;
+ tvhwarn(subsys, "Unable to change directory permissions "
+ "to \"%o\" for \"%s\" (keeping \"%o\")",
+ mode, path, FILE_MODE_BITS(st.st_mode));
+ mode = FILE_MODE_BITS(st.st_mode);
+ }
+ }
+ tvhtrace(subsys, "Creating directory \"%s\" with octal permissions "
+ "\"%o\" gid %d uid %d", path, mode, gid, uid);
} else {
err = S_ISDIR(st.st_mode) ? 0 : 1;
errno = ENOTDIR;
}
if (err) {
- tvhlog(LOG_ALERT, "settings", "Unable to create dir \"%s\": %s",
- path, strerror(errno));
+ tvhalert(subsys, "Unable to create dir \"%s\": %s",
+ path, strerror(errno));
return -1;
}
path[x] = '/';