use TMP and TMPDIR for temporary files
This commit is contained in:
parent
12da55b830
commit
24302a482a
|
@ -709,21 +709,6 @@ int SMTPFileSystem::fgetattr(const char *path, struct stat *buf, fuse_file_info
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SMTPFileSystem::expandTmpDir(char *tmp)
|
|
||||||
{
|
|
||||||
std::string tmp_dir(tmp ? tmp : "/tmp/");
|
|
||||||
if (tmp) {
|
|
||||||
tmp_dir = tmp;
|
|
||||||
auto it = tmp_dir.find('~');
|
|
||||||
for (; it != std::string::npos; it = tmp_dir.find('~'))
|
|
||||||
tmp_dir.replace(it, 1, getenv("HOME"));
|
|
||||||
if (tmp_dir[tmp_dir.length() - 1] != '/')
|
|
||||||
tmp_dir += '/';
|
|
||||||
}
|
|
||||||
tmp_dir += "simple-mtpfs-XXXXXX";
|
|
||||||
return mktemp(strdup(tmp_dir.c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SMTPFileSystem::removeDir(const std::string &dirname)
|
bool SMTPFileSystem::removeDir(const std::string &dirname)
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
|
@ -749,13 +734,21 @@ bool SMTPFileSystem::removeDir(const std::string &dirname)
|
||||||
|
|
||||||
bool SMTPFileSystem::createTmpDir()
|
bool SMTPFileSystem::createTmpDir()
|
||||||
{
|
{
|
||||||
if (m_options.m_tmp_dir)
|
removeTmpDir();
|
||||||
removeTmpDir();
|
|
||||||
|
|
||||||
m_options.m_tmp_dir = expandTmpDir(getenv("TMPDIR"));
|
const char *c_tmp = getenv("TMP");
|
||||||
if (!m_options.m_tmp_dir)
|
std::string tmp_dir;
|
||||||
return false;
|
if (c_tmp) {
|
||||||
|
tmp_dir = smtpfs_realpath(c_tmp);
|
||||||
|
} else {
|
||||||
|
c_tmp = getenv("TMPDIR");
|
||||||
|
if (!c_tmp)
|
||||||
|
c_tmp = "/tmp";
|
||||||
|
tmp_dir = smtpfs_realpath(c_tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp_dir += "/simple-mtpfs-XXXXXX";
|
||||||
|
m_options.m_tmp_dir = ::mktemp(::strdup(tmp_dir.c_str()));
|
||||||
m_tmp_files_pool.setTmpDir(m_options.m_tmp_dir);
|
m_tmp_files_pool.setTmpDir(m_options.m_tmp_dir);
|
||||||
if (::mkdir(static_cast<const char*>(m_options.m_tmp_dir), S_IRWXU) != 0)
|
if (::mkdir(static_cast<const char*>(m_options.m_tmp_dir), S_IRWXU) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -114,7 +114,6 @@ public:
|
||||||
int create(const char *path, mode_t mode, fuse_file_info *file_info);
|
int create(const char *path, mode_t mode, fuse_file_info *file_info);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static char *expandTmpDir(char *tmp);
|
|
||||||
static bool removeDir(const std::string &dirname);
|
static bool removeDir(const std::string &dirname);
|
||||||
|
|
||||||
bool createTmpDir();
|
bool createTmpDir();
|
||||||
|
|
|
@ -57,14 +57,14 @@ std::string smtpfs_basename(const std::string &path)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBUSB1
|
std::string smtpfs_realpath(const std::string &path)
|
||||||
std::string smtpfs_realpath(std::string path)
|
|
||||||
{
|
{
|
||||||
char buf[PATH_MAX + 1];
|
char buf[PATH_MAX + 1];
|
||||||
char *real_path = realpath(path.c_str(), buf);
|
char *real_path = realpath(path.c_str(), buf);
|
||||||
return std::string(real_path ? buf : "");
|
return std::string(real_path ? buf : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBUSB1
|
||||||
LIBMTP_raw_device_t *smtpfs_raw_device_new_priv(libusb_device *usb_device)
|
LIBMTP_raw_device_t *smtpfs_raw_device_new_priv(libusb_device *usb_device)
|
||||||
{
|
{
|
||||||
if (!usb_device)
|
if (!usb_device)
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
std::string smtpfs_dirname(const std::string &path);
|
std::string smtpfs_dirname(const std::string &path);
|
||||||
std::string smtpfs_basename(const std::string &path);
|
std::string smtpfs_basename(const std::string &path);
|
||||||
|
std::string smtpfs_realpath(const std::string &path);
|
||||||
|
|
||||||
bool smtpfs_check_dir(const std::string &path);
|
bool smtpfs_check_dir(const std::string &path);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue