free space check linux + mac

This commit is contained in:
David Kocik 2019-12-19 16:27:48 +01:00
parent 7b95ec486f
commit 8d52663871

View file

@ -20,6 +20,7 @@ GUID WceusbshGUID = { 0x25dbce51, 0x6c8f, 0x4a72,
#include <glob.h> #include <glob.h>
#include <libgen.h> #include <libgen.h>
#include <pwd.h> #include <pwd.h>
#include <filesystem>
#endif #endif
namespace Slic3r { namespace Slic3r {
@ -309,20 +310,27 @@ void RemovableDriveManager::inspect_file(const std::string &path, const std::str
//if not same file system - could be removable drive //if not same file system - could be removable drive
if(!compare_filesystem_id(path, parent_path)) if(!compare_filesystem_id(path, parent_path))
{ {
//user id //free space
struct stat buf; std::filesystem::space_info fs_si = std::filesystem::space(path);
stat(path.c_str(), &buf); //std::cout << "Free space: " << fs_si.free << "Available space: " << fs_si.available << " " << path << '\n';
uid_t uid = buf.st_uid; if(fs_si.free != 0 && fs_si.available != 0)
std::string username(std::getenv("USER"));
struct passwd *pw = getpwuid(uid);
if(pw != 0)
{ {
if(pw->pw_name == username) //user id
struct stat buf;
stat(path.c_str(), &buf);
uid_t uid = buf.st_uid;
std::string username(std::getenv("USER"));
struct passwd *pw = getpwuid(uid);
if(pw != 0)
{ {
std::string name = basename(const_cast<char*>(path.c_str())); if(pw->pw_name == username)
m_current_drives.push_back(DriveData(name,path)); {
std::string name = basename(const_cast<char*>(path.c_str()));
m_current_drives.push_back(DriveData(name,path));
}
} }
} }
} }
} }
bool RemovableDriveManager::compare_filesystem_id(const std::string &path_a, const std::string &path_b) bool RemovableDriveManager::compare_filesystem_id(const std::string &path_a, const std::string &path_b)