* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#define _GNU_SOURCE
#include <sys/stat.h>
+#include <strings.h>
+#include <unistd.h>
#include "settings.h"
static void
dvr_config_storage_check(dvr_config_t *cfg)
{
- char buf[PATH_MAX];
+ char home_dir[PATH_MAX + sizeof("/Videos")];
+ char dvr_dir[PATH_MAX];
+ char *xdg_dir;
struct stat st;
- const char *homedir;
if(cfg->dvr_storage != NULL && cfg->dvr_storage[0])
return;
/* Try to figure out a good place to put them videos */
-
- homedir = getenv("HOME");
-
- if(homedir != NULL) {
- snprintf(buf, sizeof(buf), "%s/Videos", homedir);
- if(stat(buf, &st) == 0 && S_ISDIR(st.st_mode))
- cfg->dvr_storage = strdup(buf);
-
- else if(stat(homedir, &st) == 0 && S_ISDIR(st.st_mode))
- cfg->dvr_storage = strdup(homedir);
- else
- cfg->dvr_storage = strdup(getcwd(buf, sizeof(buf)));
+ snprintf(home_dir, sizeof(home_dir), "%s/Videos", getenv("HOME"));
+ xdg_dir = hts_settings_get_xdg_dir_with_fallback("VIDEOS", home_dir);
+ if (xdg_dir != NULL) {
+ if (stat(xdg_dir, &st) == 0) {
+ if (S_ISLNK(st.st_mode)) {
+ char xdg_dir_link[PATH_MAX - sizeof('\0')];
+
+ if (readlink(xdg_dir, xdg_dir_link, sizeof(xdg_dir_link)) == -1)
+ tvhwarn(LS_DVR, "symlink '%s' error: %s\n", xdg_dir, strerror(errno));
+ else
+ strncpy(dvr_dir, xdg_dir_link, sizeof(dvr_dir));
+ } else if (S_ISDIR(st.st_mode)) {
+ strncpy(dvr_dir, xdg_dir, sizeof(dvr_dir) - sizeof('\0'));
+ }
+ }
+ free(xdg_dir);
}
+ if((stat(dvr_dir, &st) == 0) && S_ISDIR(st.st_mode))
+ cfg->dvr_storage = strndup(dvr_dir, PATH_MAX);
+ else if(stat(home_dir, &st) == 0 && S_ISDIR(st.st_mode))
+ cfg->dvr_storage = strndup(home_dir, sizeof(home_dir));
+ else
+ cfg->dvr_storage = get_current_dir_name();
+
tvhwarn(LS_DVR,
"Output directory for video recording is not yet configured "
"for DVR configuration \"%s\". "