mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 09:17:52 -06:00
linux owner checking
This commit is contained in:
parent
f651c7b7ec
commit
73ba196e78
1 changed files with 20 additions and 4 deletions
|
@ -154,7 +154,10 @@ void RemovableDriveManager::search_for_drives()
|
||||||
std::string path(std::getenv("USER"));
|
std::string path(std::getenv("USER"));
|
||||||
std::string pp(path);
|
std::string pp(path);
|
||||||
//std::cout << "user: "<< path << "\n";
|
//std::cout << "user: "<< path << "\n";
|
||||||
if(path == "root"){ //if program is run with sudo, we have to search for all users
|
//if program is run with sudo, we have to search for all users
|
||||||
|
// but do we want that?
|
||||||
|
/*
|
||||||
|
if(path == "root"){
|
||||||
while (true) {
|
while (true) {
|
||||||
passwd* entry = getpwent();
|
passwd* entry = getpwent();
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
|
@ -174,6 +177,7 @@ void RemovableDriveManager::search_for_drives()
|
||||||
}
|
}
|
||||||
endpwent();
|
endpwent();
|
||||||
}else
|
}else
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
//search /media/USERNAME/* folder
|
//search /media/USERNAME/* folder
|
||||||
pp = "/media/"+pp;
|
pp = "/media/"+pp;
|
||||||
|
@ -187,7 +191,7 @@ void RemovableDriveManager::search_for_drives()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//std::cout << "found drives:" <<m_current_drives.size() << "\n";
|
std::cout << "found drives:" <<m_current_drives.size() << "\n";
|
||||||
}
|
}
|
||||||
void RemovableDriveManager::search_path(const std::string &path,const std::string &parent_path)
|
void RemovableDriveManager::search_path(const std::string &path,const std::string &parent_path)
|
||||||
{
|
{
|
||||||
|
@ -201,8 +205,20 @@ void RemovableDriveManager::search_path(const std::string &path,const std::strin
|
||||||
//if not same file system - could be removable drive
|
//if not same file system - could be removable drive
|
||||||
if(!compare_filesystem_id(globbuf.gl_pathv[i], parent_path))
|
if(!compare_filesystem_id(globbuf.gl_pathv[i], parent_path))
|
||||||
{
|
{
|
||||||
std::string name = basename(globbuf.gl_pathv[i]);
|
//user id
|
||||||
m_current_drives.push_back(DriveData(name,globbuf.gl_pathv[i]));
|
struct stat buf;
|
||||||
|
stat(globbuf.gl_pathv[i],&buf);
|
||||||
|
uid_t uid = buf.st_uid;
|
||||||
|
std::string username(std::getenv("USER"));
|
||||||
|
struct passwd *pw = getpwuid(uid);
|
||||||
|
if(pw != 0)
|
||||||
|
{
|
||||||
|
if(pw->pw_name == username)
|
||||||
|
{
|
||||||
|
std::string name = basename(globbuf.gl_pathv[i]);
|
||||||
|
m_current_drives.push_back(DriveData(name,globbuf.gl_pathv[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else
|
}else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue