57 lines
1.0 KiB
C++
57 lines
1.0 KiB
C++
|
|
#include <dirent.h>
|
|
#include <sys/stat.h>
|
|
#include <stdlib.h>
|
|
#include <libsaria/path.h>
|
|
|
|
#include <iostream>
|
|
using namespace std;
|
|
|
|
/* I want to use the d_type field in a dirent */
|
|
#ifndef __USE_BSD
|
|
#define __USE_BSD
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
static string SARIA_DIR = "/saria-debug";
|
|
#else /* DEBUG */
|
|
static string SARIA_DIR = "/saria";
|
|
#endif /* DEBUG */
|
|
|
|
string get_saria_dir()
|
|
{
|
|
string saria = getenv("HOME");
|
|
string xdg = getenv("XDG_CONFIG_HOME");
|
|
|
|
if (xdg == "")
|
|
saria += "/.config";
|
|
else if (xdg.compare(0, saria.size(), saria) == 0)
|
|
saria = xdg + "/";
|
|
else
|
|
saria += "/" + xdg += "/";
|
|
|
|
return saria += SARIA_DIR;
|
|
}
|
|
|
|
void make_saria_dir()
|
|
{
|
|
string saria = get_saria_dir();
|
|
mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
|
mkdir(saria.c_str(), mode);
|
|
}
|
|
|
|
bool exists(string path)
|
|
{
|
|
struct stat stat;
|
|
return lstat(path.c_str(), &stat) == 0;
|
|
}
|
|
|
|
sid_t lookup_songid(string &filepath)
|
|
{
|
|
struct stat stat;
|
|
int err = lstat(filepath.c_str(), &stat);
|
|
if (err != 0)
|
|
return err;
|
|
return stat.st_ino;
|
|
}
|