introduce mount directory check

This commit is contained in:
Peter Hatina 2013-09-24 13:49:42 +02:00
parent 2392b471c5
commit 23e6394ed2
3 changed files with 18 additions and 0 deletions

View File

@ -395,6 +395,9 @@ bool SMTPFileSystem::exec()
if (!m_options.m_good)
return false;
if (!smtpfs_check_dir(m_options.m_mount_point))
return false;
if (m_options.m_version || m_options.m_help)
return true;

View File

@ -24,6 +24,7 @@
#endif // HAVE_LIBUSB1
extern "C" {
# include <libgen.h>
# include <sys/stat.h>
}
#ifdef HAVE_LIBUSB1
# include <climits>
@ -145,3 +146,15 @@ void smtpfs_raw_device_free(LIBMTP_raw_device_t *device)
free(static_cast<void*>(device));
}
#endif // HAVE_LIBUSB1
bool smtpfs_check_dir(const std::string &path)
{
struct stat buf;
if (::stat(path.c_str(), &buf) == 0 && S_ISDIR(buf.st_mode)
&& ::access(path.c_str(), R_OK | W_OK | X_OK) == 0)
{
return true;
}
return false;
}

View File

@ -28,6 +28,8 @@
std::string smtpfs_dirname(const std::string &path);
std::string smtpfs_basename(const std::string &path);
bool smtpfs_check_dir(const std::string &path);
#ifdef HAVE_LIBUSB1
LIBMTP_raw_device_t *smtpfs_raw_device_new(const std::string &path);
void smtpfs_raw_device_free(LIBMTP_raw_device_t *device);