2012-09-22 10:42:50 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2013-11-18 18:09:45 +00:00
|
|
|
* Copyright (C) 2012-2013, Peter Hatina <phatina@gmail.com>
|
2012-09-22 10:42:50 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <iostream>
|
|
|
|
extern "C" {
|
|
|
|
# include <dirent.h>
|
|
|
|
# include <errno.h>
|
|
|
|
# include <fcntl.h>
|
2013-01-09 17:14:33 +00:00
|
|
|
# include <fuse/fuse_opt.h>
|
2012-09-22 10:42:50 +00:00
|
|
|
# include <libgen.h>
|
|
|
|
# include <unistd.h>
|
|
|
|
# include <stddef.h>
|
|
|
|
# include <stdlib.h>
|
|
|
|
# include <sys/stat.h>
|
|
|
|
# include <sys/types.h>
|
|
|
|
}
|
|
|
|
#include "simple-mtpfs-fuse.h"
|
|
|
|
#include "simple-mtpfs-log.h"
|
2013-09-17 19:43:36 +00:00
|
|
|
#include "simple-mtpfs-util.h"
|
2012-09-22 10:42:50 +00:00
|
|
|
|
|
|
|
int wrap_getattr(const char *path, struct stat *statbuf)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->getattr(path, statbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_mknod(const char *path, mode_t mode, dev_t dev)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->mknod(path, mode, dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_mkdir(const char *path, mode_t mode)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->mkdir(path, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_unlink(const char *path)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->unlink(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_rmdir(const char *path)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->rmdir(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_rename(const char *path, const char *newpath)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->rename(path, newpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_chmod(const char *path, mode_t mode)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->chmod(path, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_chown(const char *path, uid_t uid, gid_t gid)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->chown(path, uid, gid);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_truncate(const char *path, off_t new_size)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->truncate(path, new_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_utime(const char *path, struct utimbuf *ubuf)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->utime(path, ubuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_open(const char *path, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->open(path, file_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_read(const char *path, char *buf, size_t size, off_t offset,
|
|
|
|
struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->read(path, buf, size, offset, file_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_write(const char *path, const char *buf, size_t size, off_t offset,
|
|
|
|
struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->write(path, buf, size, offset, file_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_statfs(const char *path, struct statvfs *stat_info)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->statfs(path, stat_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_flush(const char *path, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->flush(path, file_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_release(const char *path, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->release(path, file_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_fsync(const char *path, int datasync, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->fsync(path, datasync, file_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_opendir(const char *path, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->opendir(path, file_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
|
|
|
|
off_t offset, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->readdir(path, buf, filler,
|
|
|
|
offset, file_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_releasedir(const char *path, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->releasedir(path, file_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_fsyncdir(const char *path, int datasync, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->fsyncdir(path, datasync, file_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* wrap_init(struct fuse_conn_info *conn)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->init(conn);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wrap_create(const char *path, mode_t mode, fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->create(path, mode, file_info);
|
|
|
|
}
|
|
|
|
|
2012-10-02 16:50:46 +00:00
|
|
|
int wrap_ftruncate(const char *path, off_t offset, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return SMTPFileSystem::instance()->ftruncate(path, offset, file_info);
|
|
|
|
}
|
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2013-09-17 19:43:36 +00:00
|
|
|
SMTPFileSystem::SMTPFileSystemOptions::SMTPFileSystemOptions()
|
|
|
|
: m_good(false)
|
|
|
|
, m_help(false)
|
|
|
|
, m_version(false)
|
|
|
|
, m_verbose(false)
|
|
|
|
, m_enable_move(false)
|
|
|
|
, m_list_devices(false)
|
|
|
|
, m_device_no(1)
|
|
|
|
, m_tmp_dir(nullptr)
|
|
|
|
#ifdef HAVE_LIBUSB1
|
|
|
|
, m_device_file(nullptr)
|
|
|
|
#endif // HAVE_LIBUSB1
|
2013-09-17 20:38:30 +00:00
|
|
|
, m_mount_point(nullptr)
|
2013-09-17 19:43:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SMTPFileSystem::SMTPFileSystemOptions::~SMTPFileSystemOptions()
|
|
|
|
{
|
|
|
|
free(static_cast<void*>(m_tmp_dir));
|
|
|
|
#ifdef HAVE_LIBUSB1
|
|
|
|
free(static_cast<void*>(m_device_file));
|
|
|
|
#endif // HAVE_LIBUSB1
|
2013-09-17 20:38:30 +00:00
|
|
|
free(static_cast<void*>(m_mount_point));
|
2013-09-17 19:43:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
int SMTPFileSystem::SMTPFileSystemOptions::opt_proc(void *data, const char *arg, int key,
|
|
|
|
struct fuse_args *outargs)
|
|
|
|
{
|
|
|
|
SMTPFileSystemOptions *options = static_cast<SMTPFileSystemOptions*>(data);
|
|
|
|
|
|
|
|
if (key == FUSE_OPT_KEY_NONOPT) {
|
2013-09-17 20:38:30 +00:00
|
|
|
#ifdef HAVE_LIBUSB1
|
|
|
|
if (options->m_mount_point && !options->m_device_file) {
|
2013-09-17 19:43:36 +00:00
|
|
|
options->m_device_file = options->m_mount_point;
|
|
|
|
options->m_mount_point = nullptr;
|
2013-09-17 20:38:30 +00:00
|
|
|
} else if (options->m_mount_point && options->m_device_file) {
|
|
|
|
// Unknown positional argument supplied
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (options->m_mount_point) {
|
|
|
|
// Unknown positional argument supplied
|
|
|
|
return -1;
|
2013-09-17 19:43:36 +00:00
|
|
|
}
|
2013-09-17 20:38:30 +00:00
|
|
|
#endif //HAVE_LIBUSB1
|
|
|
|
|
2013-09-17 19:43:36 +00:00
|
|
|
fuse_opt_add_opt(&options->m_mount_point, arg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
std::unique_ptr<SMTPFileSystem> SMTPFileSystem::s_instance;
|
|
|
|
|
|
|
|
SMTPFileSystem *SMTPFileSystem::instance()
|
|
|
|
{
|
|
|
|
if (!s_instance.get())
|
2012-09-23 11:59:27 +00:00
|
|
|
s_instance.reset(new SMTPFileSystem());
|
2012-09-22 10:42:50 +00:00
|
|
|
return s_instance.get();
|
|
|
|
}
|
|
|
|
|
2012-09-23 11:59:27 +00:00
|
|
|
SMTPFileSystem::SMTPFileSystem():
|
2012-09-22 10:42:50 +00:00
|
|
|
m_args(),
|
|
|
|
m_tmp_files_pool(),
|
|
|
|
m_options(),
|
|
|
|
m_device()
|
|
|
|
{
|
|
|
|
m_fuse_operations.getattr = wrap_getattr;
|
|
|
|
m_fuse_operations.readlink = nullptr;
|
|
|
|
m_fuse_operations.getdir = nullptr;
|
|
|
|
m_fuse_operations.mknod = wrap_mknod;
|
|
|
|
m_fuse_operations.mkdir = wrap_mkdir;
|
|
|
|
m_fuse_operations.unlink = wrap_unlink;
|
|
|
|
m_fuse_operations.rmdir = wrap_rmdir;
|
|
|
|
m_fuse_operations.symlink = nullptr;
|
|
|
|
m_fuse_operations.rename = wrap_rename;
|
|
|
|
m_fuse_operations.link = nullptr;
|
|
|
|
m_fuse_operations.chmod = wrap_chmod;
|
|
|
|
m_fuse_operations.chown = wrap_chown;
|
|
|
|
m_fuse_operations.truncate = wrap_truncate;
|
|
|
|
m_fuse_operations.utime = wrap_utime;
|
|
|
|
m_fuse_operations.open = wrap_open;
|
|
|
|
m_fuse_operations.read = wrap_read;
|
|
|
|
m_fuse_operations.write = wrap_write;
|
|
|
|
m_fuse_operations.statfs = wrap_statfs;
|
|
|
|
m_fuse_operations.flush = wrap_flush;
|
|
|
|
m_fuse_operations.release = wrap_release;
|
|
|
|
m_fuse_operations.fsync = wrap_fsync;
|
|
|
|
m_fuse_operations.setxattr = nullptr;
|
|
|
|
m_fuse_operations.getxattr = nullptr;
|
|
|
|
m_fuse_operations.listxattr = nullptr;
|
|
|
|
m_fuse_operations.removexattr = nullptr;
|
|
|
|
m_fuse_operations.opendir = wrap_opendir;
|
|
|
|
m_fuse_operations.readdir = wrap_readdir;
|
|
|
|
m_fuse_operations.releasedir = wrap_releasedir;
|
|
|
|
m_fuse_operations.fsyncdir = wrap_fsyncdir;
|
|
|
|
m_fuse_operations.init = wrap_init;
|
|
|
|
m_fuse_operations.destroy = nullptr;
|
|
|
|
m_fuse_operations.access = nullptr;
|
|
|
|
m_fuse_operations.create = wrap_create;
|
2012-10-02 16:50:46 +00:00
|
|
|
m_fuse_operations.ftruncate = wrap_ftruncate;
|
2013-11-17 15:27:18 +00:00
|
|
|
m_fuse_operations.fgetattr = nullptr;
|
2012-09-22 10:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SMTPFileSystem::~SMTPFileSystem()
|
|
|
|
{
|
|
|
|
fuse_opt_free_args(&m_args);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SMTPFileSystem::parseOptions(int argc, char **argv)
|
|
|
|
{
|
|
|
|
#define SMTPFS_OPT_KEY(t, p, v) { t, offsetof(SMTPFileSystemOptions, p), v }
|
|
|
|
|
|
|
|
static struct fuse_opt smtpfs_opts[] = {
|
|
|
|
SMTPFS_OPT_KEY("enable-move", m_enable_move, 1),
|
2013-09-17 19:43:36 +00:00
|
|
|
SMTPFS_OPT_KEY("--device %i", m_device_no, 0),
|
2012-09-22 10:42:50 +00:00
|
|
|
SMTPFS_OPT_KEY("-l", m_list_devices, 1),
|
|
|
|
SMTPFS_OPT_KEY("--list-devices", m_list_devices, 1),
|
|
|
|
SMTPFS_OPT_KEY("-v", m_verbose, 1),
|
|
|
|
SMTPFS_OPT_KEY("--verbose", m_verbose, 1),
|
2012-09-23 11:59:27 +00:00
|
|
|
SMTPFS_OPT_KEY("-V", m_version, 1),
|
|
|
|
SMTPFS_OPT_KEY("--version", m_version, 1),
|
|
|
|
SMTPFS_OPT_KEY("-h", m_help, 1),
|
|
|
|
SMTPFS_OPT_KEY("--help", m_help, 1),
|
2012-09-22 10:42:50 +00:00
|
|
|
FUSE_OPT_END
|
|
|
|
};
|
|
|
|
|
2012-09-23 11:59:27 +00:00
|
|
|
if (argc < 2) {
|
2013-11-25 19:44:31 +00:00
|
|
|
logerr("Wrong usage.\n");
|
2012-09-23 11:59:27 +00:00
|
|
|
m_options.m_good = false;
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-22 10:42:50 +00:00
|
|
|
|
|
|
|
fuse_opt_free_args(&m_args);
|
|
|
|
m_args = FUSE_ARGS_INIT(argc, argv);
|
2013-09-17 20:38:30 +00:00
|
|
|
if (fuse_opt_parse(&m_args, &m_options, smtpfs_opts, SMTPFileSystemOptions::opt_proc) == -1) {
|
2012-09-23 11:59:27 +00:00
|
|
|
m_options.m_good = false;
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-22 10:42:50 +00:00
|
|
|
|
2012-09-23 11:59:27 +00:00
|
|
|
if (m_options.m_version || m_options.m_help || m_options.m_list_devices) {
|
|
|
|
m_options.m_good = true;
|
2012-09-22 10:42:50 +00:00
|
|
|
return true;
|
2012-09-23 11:59:27 +00:00
|
|
|
}
|
2012-09-22 10:42:50 +00:00
|
|
|
|
2013-09-17 19:43:36 +00:00
|
|
|
if (--m_options.m_device_no < 0) {
|
2013-11-25 19:44:31 +00:00
|
|
|
logerr("Device number must be positive number greater than 0.\n");
|
2012-09-23 11:59:27 +00:00
|
|
|
m_options.m_good = false;
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-22 10:42:50 +00:00
|
|
|
|
2013-11-25 19:22:46 +00:00
|
|
|
if (!m_options.m_mount_point) {
|
2013-11-25 19:44:31 +00:00
|
|
|
logerr("Mount point missing.\n");
|
2013-11-25 19:22:46 +00:00
|
|
|
m_options.m_good = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fuse_opt_add_arg(&m_args, m_options.m_mount_point);
|
2013-09-17 19:43:36 +00:00
|
|
|
fuse_opt_add_arg(&m_args, "-s");
|
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
if (m_options.m_verbose) {
|
|
|
|
Logger::setGlobalVerbose();
|
|
|
|
fuse_opt_add_arg(&m_args, "-f");
|
|
|
|
}
|
|
|
|
|
2013-09-17 19:43:36 +00:00
|
|
|
#ifdef HAVE_LIBUSB1
|
|
|
|
// device file and -- device are mutually exclusive, fail if both set
|
|
|
|
if (m_options.m_device_no && m_options.m_device_file) {
|
|
|
|
m_options.m_good = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif // HAVE_LIBUSB1
|
|
|
|
|
2012-09-23 11:59:27 +00:00
|
|
|
m_options.m_good = true;
|
2012-09-22 10:42:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-23 11:59:27 +00:00
|
|
|
void SMTPFileSystem::printHelp() const
|
|
|
|
{
|
|
|
|
struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
|
|
|
|
struct fuse_operations tmp_operations;
|
2012-10-02 19:37:18 +00:00
|
|
|
memset(&tmp_operations, 0, sizeof(tmp_operations));
|
2013-10-29 20:26:40 +00:00
|
|
|
std::cerr << "usage: " << m_args.argv[0]
|
2013-09-17 19:43:36 +00:00
|
|
|
#ifdef HAVE_LIBUSB1
|
|
|
|
<< " <source>"
|
|
|
|
#endif // HAVE_LIBUSB1
|
|
|
|
<< " mountpoint [options]\n\n"
|
2012-09-23 11:59:27 +00:00
|
|
|
<< "general options:\n"
|
|
|
|
<< " -o opt,[opt...] mount options\n"
|
|
|
|
<< " -h --help print help\n"
|
|
|
|
<< " -V --version print version\n\n"
|
|
|
|
<< "simple-mtpfs options:\n"
|
|
|
|
<< " -l --list-devices print available devices\n"
|
|
|
|
<< " --device select a device number to mount\n"
|
2013-06-11 17:56:02 +00:00
|
|
|
<< " -o enable-move enable the move operations\n\n";
|
2012-09-23 11:59:27 +00:00
|
|
|
fuse_opt_add_arg(&args, m_args.argv[0]);
|
|
|
|
fuse_opt_add_arg(&args, "-ho");
|
|
|
|
fuse_main(args.argc, args.argv, &tmp_operations, nullptr);
|
|
|
|
fuse_opt_free_args(&args);
|
2013-10-29 20:26:40 +00:00
|
|
|
std::cerr << "\nReport bugs to <" << PACKAGE_BUGREPORT << ">.\n";
|
2012-09-23 11:59:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SMTPFileSystem::printVersion() const
|
|
|
|
{
|
|
|
|
struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
|
|
|
|
struct fuse_operations tmp_operations;
|
2012-10-02 19:37:18 +00:00
|
|
|
memset(&tmp_operations, 0, sizeof(tmp_operations));
|
2012-09-23 11:59:27 +00:00
|
|
|
fuse_opt_add_arg(&args, m_args.argv[0]);
|
|
|
|
fuse_opt_add_arg(&args, "--version");
|
|
|
|
std::cout << "simple-mtpfs version " << VERSION << "\n";
|
|
|
|
fuse_main(args.argc, args.argv, &tmp_operations, nullptr);
|
|
|
|
fuse_opt_free_args(&args);
|
|
|
|
}
|
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
bool SMTPFileSystem::exec()
|
|
|
|
{
|
|
|
|
if (!m_options.m_good)
|
|
|
|
return false;
|
|
|
|
|
2012-09-23 11:59:27 +00:00
|
|
|
if (m_options.m_version || m_options.m_help)
|
|
|
|
return true;
|
|
|
|
|
2013-11-25 19:44:31 +00:00
|
|
|
if (!smtpfs_check_dir(m_options.m_mount_point)) {
|
|
|
|
logerr("Can not mount the device to '", m_options.m_mount_point, "'.\n");
|
2013-10-18 12:49:02 +00:00
|
|
|
return false;
|
2013-11-25 19:44:31 +00:00
|
|
|
}
|
2013-10-18 12:49:02 +00:00
|
|
|
|
2013-11-25 19:44:31 +00:00
|
|
|
if (!createTmpDir()) {
|
|
|
|
logerr("Can not create a temporary directory.\n");
|
2013-09-24 12:27:43 +00:00
|
|
|
return false;
|
2013-11-25 19:44:31 +00:00
|
|
|
}
|
2013-09-24 12:27:43 +00:00
|
|
|
|
2013-09-17 19:43:36 +00:00
|
|
|
#ifdef HAVE_LIBUSB1
|
|
|
|
if (m_options.m_device_file) {
|
|
|
|
// Try to use device file first, if provided
|
2013-11-25 19:44:31 +00:00
|
|
|
if (!m_device.connect(m_options.m_device_file)) {
|
|
|
|
logerr("Can not connect to device '", m_options.m_device_file, "'.\n");
|
2013-09-17 19:43:36 +00:00
|
|
|
return false;
|
2013-11-25 19:44:31 +00:00
|
|
|
}
|
2013-09-17 19:43:36 +00:00
|
|
|
} else
|
|
|
|
#endif // HAVE_LIBUSB1
|
|
|
|
{
|
|
|
|
// Connect to MTP device by order number, if no device file supplied
|
2013-11-25 19:44:31 +00:00
|
|
|
if (!m_device.connect(m_options.m_device_no)) {
|
|
|
|
logerr("Can not connect to device no. ", m_options.m_device_no, ".\n");
|
2013-09-17 19:43:36 +00:00
|
|
|
return false;
|
2013-11-25 19:44:31 +00:00
|
|
|
}
|
2013-09-17 19:43:36 +00:00
|
|
|
}
|
2012-09-22 10:42:50 +00:00
|
|
|
m_device.enableMove(m_options.m_enable_move);
|
2013-11-25 19:44:31 +00:00
|
|
|
if (fuse_main(m_args.argc, m_args.argv, &m_fuse_operations, nullptr) > 0) {
|
2012-09-22 10:42:50 +00:00
|
|
|
return false;
|
2013-11-25 19:44:31 +00:00
|
|
|
}
|
2012-09-22 10:42:50 +00:00
|
|
|
m_device.disconnect();
|
2013-09-24 12:27:43 +00:00
|
|
|
|
|
|
|
removeTmpDir();
|
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* SMTPFileSystem::init(struct fuse_conn_info *conn)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::getattr(const char *path, struct stat *buf)
|
|
|
|
{
|
|
|
|
memset(buf, 0, sizeof(struct stat));
|
|
|
|
struct fuse_context *fc = fuse_get_context();
|
|
|
|
buf->st_uid = fc->uid;
|
|
|
|
buf->st_gid = fc->gid;
|
|
|
|
if (path == std::string("/")) {
|
|
|
|
buf->st_mode = S_IFDIR | 0775;
|
|
|
|
buf->st_nlink = 2;
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
std::string tmp_path(smtpfs_dirname(path));
|
|
|
|
std::string tmp_file(smtpfs_basename(path));
|
|
|
|
const TypeDir *content = m_device.dirFetchContent(tmp_path);
|
2013-09-24 20:22:56 +00:00
|
|
|
if (!content) {
|
2013-11-07 08:15:37 +00:00
|
|
|
return -ENOENT;
|
2013-09-24 20:22:56 +00:00
|
|
|
}
|
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
if (content->dir(tmp_file)) {
|
|
|
|
const TypeDir *dir = content->dir(tmp_file);
|
|
|
|
buf->st_ino = dir->id();
|
|
|
|
buf->st_mode = S_IFDIR | 0775;
|
|
|
|
buf->st_nlink = 2;
|
|
|
|
} else if (content->file(tmp_file)) {
|
|
|
|
const TypeFile *file = content->file(tmp_file);
|
|
|
|
buf->st_ino = file->id();
|
|
|
|
buf->st_size = file->size();
|
|
|
|
buf->st_blocks = (file->size() / 512) + (file->size() % 512 > 0 ? 1 : 0);
|
|
|
|
buf->st_nlink = 1;
|
2013-11-17 15:35:28 +00:00
|
|
|
buf->st_mode = S_IFREG | 0644;
|
2012-09-22 10:42:50 +00:00
|
|
|
buf->st_mtime = file->modificationDate();
|
|
|
|
buf->st_ctime = buf->st_mtime;
|
|
|
|
buf->st_atime = buf->st_mtime;
|
|
|
|
} else {
|
2013-11-07 08:15:37 +00:00
|
|
|
return -ENOENT;
|
2012-09-22 10:42:50 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-24 20:22:56 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::mknod(const char *path, mode_t mode, dev_t dev)
|
|
|
|
{
|
2013-11-07 08:15:37 +00:00
|
|
|
if (!S_ISREG(mode))
|
|
|
|
return -EINVAL;
|
2013-09-24 20:20:53 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
std::string tmp_path = m_tmp_files_pool.makeTmpPath(std::string(path));
|
|
|
|
int rval = ::open(tmp_path.c_str(), O_CREAT | O_WRONLY, mode);
|
|
|
|
if (rval < 0)
|
2013-11-07 08:15:37 +00:00
|
|
|
return -errno;
|
2013-09-24 20:20:53 +00:00
|
|
|
|
|
|
|
rval = ::close(rval);
|
2012-09-22 10:42:50 +00:00
|
|
|
if (rval < 0)
|
2013-11-07 08:15:37 +00:00
|
|
|
return -errno;
|
2013-09-24 20:20:53 +00:00
|
|
|
|
2012-10-02 16:22:24 +00:00
|
|
|
m_device.filePush(tmp_path, std::string(path));
|
|
|
|
::unlink(tmp_path.c_str());
|
2013-09-24 20:20:53 +00:00
|
|
|
return 0;
|
2012-09-22 10:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::mkdir(const char *path, mode_t mode)
|
|
|
|
{
|
|
|
|
return m_device.dirCreateNew(std::string(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::unlink(const char *path)
|
|
|
|
{
|
|
|
|
return m_device.fileRemove(std::string(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::rmdir(const char *path)
|
|
|
|
{
|
|
|
|
return m_device.dirRemove(std::string(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::rename(const char *path, const char *newpath)
|
|
|
|
{
|
|
|
|
const std::string tmp_old_dirname(smtpfs_dirname(std::string(path)));
|
|
|
|
const std::string tmp_new_dirname(smtpfs_dirname(std::string(newpath)));
|
|
|
|
if (tmp_old_dirname == tmp_new_dirname)
|
|
|
|
return m_device.rename(std::string(path), std::string(newpath));
|
|
|
|
|
2013-11-07 08:15:37 +00:00
|
|
|
if (!m_options.m_enable_move)
|
|
|
|
return -EPERM;
|
2012-09-22 10:42:50 +00:00
|
|
|
|
|
|
|
const std::string tmp_file = m_tmp_files_pool.makeTmpPath(std::string(newpath));
|
|
|
|
int rval = m_device.filePull(std::string(path), tmp_file);
|
2013-11-07 08:15:37 +00:00
|
|
|
if (rval != 0)
|
|
|
|
return -rval;
|
2013-09-24 20:19:23 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
rval = m_device.filePush(tmp_file, std::string(newpath));
|
2013-11-07 08:15:37 +00:00
|
|
|
if (rval != 0)
|
|
|
|
return -rval;
|
2013-09-24 20:19:23 +00:00
|
|
|
|
2012-09-23 12:11:32 +00:00
|
|
|
rval = m_device.fileRemove(std::string(path));
|
2013-11-07 08:15:37 +00:00
|
|
|
if (rval != 0)
|
|
|
|
return -rval;
|
2013-09-24 20:19:23 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::chmod(const char *path, mode_t mode)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::chown(const char *path, uid_t uid, gid_t gid)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::truncate(const char *path, off_t new_size)
|
|
|
|
{
|
2012-10-02 16:20:50 +00:00
|
|
|
const std::string tmp_path = m_tmp_files_pool.makeTmpPath(std::string(path));
|
|
|
|
int rval = m_device.filePull(std::string(path), tmp_path);
|
2013-09-24 19:44:07 +00:00
|
|
|
if (rval != 0) {
|
|
|
|
::unlink(tmp_path.c_str());
|
2013-11-07 08:15:37 +00:00
|
|
|
return -rval;
|
2013-09-24 19:44:07 +00:00
|
|
|
}
|
|
|
|
|
2012-10-02 16:20:50 +00:00
|
|
|
rval = ::truncate(tmp_path.c_str(), new_size);
|
2013-09-24 19:44:07 +00:00
|
|
|
if (rval != 0) {
|
2013-11-07 08:15:37 +00:00
|
|
|
int errno_tmp = errno;
|
2013-09-24 19:44:07 +00:00
|
|
|
::unlink(tmp_path.c_str());
|
2013-11-07 08:15:37 +00:00
|
|
|
return -errno_tmp;
|
2013-09-24 19:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rval = m_device.fileRemove(std::string(path));
|
|
|
|
if (rval != 0) {
|
|
|
|
::unlink(tmp_path.c_str());
|
2013-11-07 08:15:37 +00:00
|
|
|
return -rval;
|
2013-09-24 19:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rval = m_device.filePush(tmp_path, std::string(path));
|
|
|
|
::unlink(tmp_path.c_str());
|
|
|
|
|
2013-11-07 08:15:37 +00:00
|
|
|
if (rval != 0)
|
|
|
|
return -rval;
|
2013-09-24 19:44:07 +00:00
|
|
|
|
|
|
|
return 0;
|
2012-09-22 10:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::utime(const char *path, struct utimbuf *ubuf)
|
|
|
|
{
|
|
|
|
std::string tmp_basename(smtpfs_basename(std::string(path)));
|
|
|
|
std::string tmp_dirname(smtpfs_dirname(std::string(path)));
|
2013-09-24 19:47:12 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
const TypeDir *parent = m_device.dirFetchContent(tmp_dirname);
|
2013-11-07 08:15:37 +00:00
|
|
|
if (!parent)
|
|
|
|
return -ENOENT;
|
2013-09-24 19:47:12 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
const TypeFile *file = parent->file(tmp_basename);
|
2013-11-07 08:15:37 +00:00
|
|
|
if (!file)
|
|
|
|
return -ENOENT;
|
2013-09-24 19:47:12 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
const_cast<TypeFile*>(file)->setModificationDate(ubuf->modtime);
|
2013-09-24 19:47:12 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::create(const char *path, mode_t mode, fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
const std::string tmp_path = m_tmp_files_pool.makeTmpPath(std::string(path));
|
2013-09-24 19:48:40 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
int rval = ::creat(tmp_path.c_str(), mode);
|
|
|
|
if (rval < 0)
|
2013-11-07 08:15:37 +00:00
|
|
|
return -errno;
|
2013-09-24 19:48:40 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
file_info->fh = rval;
|
|
|
|
m_tmp_files_pool.addFile(TypeTmpFile(std::string(path), tmp_path, rval, true));
|
|
|
|
m_device.filePush(tmp_path, std::string(path));
|
2013-09-24 19:48:40 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::open(const char *path, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
if (file_info->flags & O_WRONLY)
|
|
|
|
file_info->flags |= O_TRUNC;
|
|
|
|
|
|
|
|
std::string tmp_file = m_tmp_files_pool.makeTmpPath(std::string(path));
|
|
|
|
int rval = m_device.filePull(std::string(path), tmp_file);
|
2013-11-07 08:15:37 +00:00
|
|
|
if (rval != 0)
|
|
|
|
return -rval;
|
2013-09-24 19:55:26 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
int fd = ::open(tmp_file.c_str(), file_info->flags);
|
|
|
|
if (fd < 0)
|
2013-11-07 08:15:37 +00:00
|
|
|
return -errno;
|
2013-09-24 19:55:26 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
file_info->fh = fd;
|
|
|
|
m_tmp_files_pool.addFile(TypeTmpFile(std::string(path), tmp_file, fd));
|
2013-09-24 19:55:26 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::read(const char *path, char *buf, size_t size,
|
|
|
|
off_t offset, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
int rval = ::pread(file_info->fh, buf, size, offset);
|
|
|
|
if (rval < 0)
|
2013-11-07 08:15:37 +00:00
|
|
|
return -errno;
|
2012-09-22 10:42:50 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::write(const char *path, const char *buf, size_t size,
|
|
|
|
off_t offset, struct fuse_file_info *file_info)
|
|
|
|
{
|
2013-09-24 19:57:13 +00:00
|
|
|
const TypeTmpFile *tmp_file = m_tmp_files_pool.getFile(static_cast<int>(file_info->fh));
|
2013-11-07 08:15:37 +00:00
|
|
|
if (!tmp_file)
|
|
|
|
return -EINVAL;
|
2013-09-24 19:57:13 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
int rval = ::pwrite(file_info->fh, buf, size, offset);
|
|
|
|
if (rval < 0)
|
2013-11-07 08:15:37 +00:00
|
|
|
return -errno;
|
2013-09-24 19:57:13 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
const_cast<TypeTmpFile*>(tmp_file)->setModified();
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::release(const char *path, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
int rval = ::close(file_info->fh);
|
|
|
|
if (rval < 0)
|
2013-11-07 08:15:37 +00:00
|
|
|
return -errno;
|
2012-09-22 10:42:50 +00:00
|
|
|
|
2012-09-29 10:30:21 +00:00
|
|
|
if (std::string(path) == std::string("-"))
|
|
|
|
return 0;
|
|
|
|
|
2012-09-29 22:16:04 +00:00
|
|
|
const TypeTmpFile *tmp_file = m_tmp_files_pool.getFile(static_cast<int>(file_info->fh));
|
2012-09-22 10:42:50 +00:00
|
|
|
const bool modif = tmp_file->isModified();
|
|
|
|
const std::string tmp_path = tmp_file->pathTmp();
|
2012-09-29 22:16:04 +00:00
|
|
|
m_tmp_files_pool.removeFile(tmp_file->fileDescriptor());
|
2012-09-22 10:42:50 +00:00
|
|
|
if (modif) {
|
2013-11-07 08:15:37 +00:00
|
|
|
int rval = m_device.filePush(tmp_path, std::string(path));
|
|
|
|
if (rval != 0) {
|
2013-09-24 20:00:27 +00:00
|
|
|
::unlink(tmp_path.c_str());
|
2013-11-07 08:15:37 +00:00
|
|
|
return -rval;
|
2013-09-24 20:00:27 +00:00
|
|
|
}
|
2012-09-22 10:42:50 +00:00
|
|
|
}
|
2013-09-24 20:00:27 +00:00
|
|
|
|
|
|
|
::unlink(tmp_path.c_str());
|
|
|
|
|
|
|
|
return 0;
|
2012-09-22 10:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::statfs(const char *path, struct statvfs *stat_info)
|
|
|
|
{
|
|
|
|
uint64_t bs = 1024;
|
2013-07-08 15:33:35 +00:00
|
|
|
// XXX: linux coreutils still use bsize member to calculate free space
|
2012-09-22 10:42:50 +00:00
|
|
|
stat_info->f_bsize = static_cast<unsigned long>(bs);
|
2013-07-08 15:33:35 +00:00
|
|
|
stat_info->f_frsize = static_cast<unsigned long>(bs);
|
2012-09-22 10:42:50 +00:00
|
|
|
stat_info->f_blocks = m_device.storageTotalSize() / bs;
|
|
|
|
stat_info->f_bavail = m_device.storageFreeSize() / bs;
|
|
|
|
stat_info->f_bfree = stat_info->f_bavail;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::flush(const char *path, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::fsync(const char *path, int datasync,
|
|
|
|
struct fuse_file_info *fi)
|
|
|
|
{
|
2013-11-07 08:15:37 +00:00
|
|
|
int rval = -1;
|
2013-06-16 12:32:54 +00:00
|
|
|
#ifdef HAVE_FDATASYNC
|
|
|
|
if (datasync)
|
2013-11-07 08:15:37 +00:00
|
|
|
rval = ::fdatasync(fi->fh);
|
2013-06-16 12:32:54 +00:00
|
|
|
else
|
2013-11-07 08:15:37 +00:00
|
|
|
#else
|
|
|
|
rval = ::fsync(fi->fh);
|
2013-06-16 12:32:54 +00:00
|
|
|
#endif
|
2013-11-07 08:15:37 +00:00
|
|
|
if (rval != 0)
|
|
|
|
return -errno;
|
|
|
|
return 0;
|
2012-09-22 10:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::opendir(const char *path, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
const TypeDir *content = m_device.dirFetchContent(std::string(path));
|
2013-11-07 08:15:37 +00:00
|
|
|
if (!content)
|
|
|
|
return -ENOENT;
|
2013-09-24 20:07:34 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::readdir(const char *path, void *buf, fuse_fill_dir_t filler,
|
|
|
|
off_t offset, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
const TypeDir *content = m_device.dirFetchContent(std::string(path));
|
2013-11-07 08:15:37 +00:00
|
|
|
if (!content)
|
|
|
|
return -ENOENT;
|
2013-09-24 20:09:13 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
const std::set<TypeDir> dirs = content->dirs();
|
|
|
|
const std::set<TypeFile> files = content->files();
|
2013-09-24 20:09:13 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
for (const TypeDir &d : dirs) {
|
|
|
|
struct stat st;
|
|
|
|
memset(&st, 0, sizeof(st));
|
|
|
|
st.st_ino = d.id();
|
|
|
|
st.st_mode = S_IFDIR | 0775;
|
|
|
|
filler(buf, d.name().c_str(), &st, 0);
|
|
|
|
}
|
2013-09-24 20:09:13 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
for (const TypeFile &f : files) {
|
|
|
|
struct stat st;
|
|
|
|
memset(&st, 0, sizeof(st));
|
|
|
|
st.st_ino = f.id();
|
2013-11-17 15:35:28 +00:00
|
|
|
st.st_mode = S_IFREG | 0644;
|
2012-09-22 10:42:50 +00:00
|
|
|
filler(buf, f.name().c_str(), &st, 0);
|
|
|
|
}
|
2013-09-24 20:09:13 +00:00
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::releasedir(const char *path, struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SMTPFileSystem::fsyncdir(const char *path, int datasync,
|
|
|
|
struct fuse_file_info *file_info)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-02 16:22:24 +00:00
|
|
|
int SMTPFileSystem::ftruncate(const char *path, off_t offset,
|
2012-09-22 10:42:50 +00:00
|
|
|
struct fuse_file_info *file_info)
|
|
|
|
{
|
2012-10-02 16:50:46 +00:00
|
|
|
const TypeTmpFile *tmp_file = m_tmp_files_pool.getFile(file_info->fh);
|
|
|
|
if (::ftruncate(file_info->fh, offset) != 0)
|
2013-11-07 08:15:37 +00:00
|
|
|
return -errno;
|
2012-10-02 16:50:46 +00:00
|
|
|
const_cast<TypeTmpFile*>(tmp_file)->setModified();
|
2012-09-22 10:42:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SMTPFileSystem::removeDir(const std::string &dirname)
|
|
|
|
{
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *entry;
|
|
|
|
std::string path;
|
|
|
|
|
|
|
|
dir = ::opendir(dirname.c_str());
|
2013-06-11 19:01:59 +00:00
|
|
|
if (!dir)
|
2012-09-22 10:42:50 +00:00
|
|
|
return false;
|
|
|
|
|
2013-06-11 19:01:59 +00:00
|
|
|
while ((entry = ::readdir(dir))) {
|
2012-09-22 10:42:50 +00:00
|
|
|
if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) {
|
|
|
|
path = dirname + "/" + entry->d_name;
|
|
|
|
if (entry->d_type == DT_DIR)
|
|
|
|
return removeDir(path);
|
|
|
|
::unlink(path.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
::closedir(dir);
|
|
|
|
::remove(dirname.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-24 12:27:43 +00:00
|
|
|
bool SMTPFileSystem::createTmpDir()
|
|
|
|
{
|
2013-09-24 13:57:41 +00:00
|
|
|
removeTmpDir();
|
2013-09-24 12:27:43 +00:00
|
|
|
|
2013-09-24 13:57:41 +00:00
|
|
|
const char *c_tmp = getenv("TMP");
|
|
|
|
std::string tmp_dir;
|
|
|
|
if (c_tmp) {
|
|
|
|
tmp_dir = smtpfs_realpath(c_tmp);
|
|
|
|
} else {
|
|
|
|
c_tmp = getenv("TMPDIR");
|
|
|
|
if (!c_tmp)
|
2013-11-18 19:11:10 +00:00
|
|
|
c_tmp = TMPDIR;
|
2013-09-24 13:57:41 +00:00
|
|
|
tmp_dir = smtpfs_realpath(c_tmp);
|
|
|
|
}
|
2013-09-24 12:27:43 +00:00
|
|
|
|
2013-09-24 13:57:41 +00:00
|
|
|
tmp_dir += "/simple-mtpfs-XXXXXX";
|
|
|
|
m_options.m_tmp_dir = ::mktemp(::strdup(tmp_dir.c_str()));
|
2013-09-24 12:27:43 +00:00
|
|
|
m_tmp_files_pool.setTmpDir(m_options.m_tmp_dir);
|
|
|
|
if (::mkdir(static_cast<const char*>(m_options.m_tmp_dir), S_IRWXU) != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-22 10:42:50 +00:00
|
|
|
bool SMTPFileSystem::removeTmpDir()
|
|
|
|
{
|
|
|
|
if (m_options.m_tmp_dir)
|
|
|
|
return removeDir(std::string(m_options.m_tmp_dir));
|
|
|
|
return false;
|
|
|
|
}
|