mirror of
https://github.com/trapexit/mergerfs.git
synced 2025-04-25 22:44:04 +08:00
37 lines
756 B
C++
37 lines
756 B
C++
#include "fs_find_mount_point.hpp"
|
|
|
|
#include "fs_lstat.hpp"
|
|
|
|
ghc::filesystem::path
|
|
fs::find_mount_point(const ghc::filesystem::path &path_)
|
|
{
|
|
int rv;
|
|
struct stat initial_st;
|
|
struct stat tmp_st;
|
|
std::error_code ec;
|
|
ghc::filesystem::path can_path;
|
|
ghc::filesystem::path tmp_path;
|
|
|
|
can_path = ghc::filesystem::weakly_canonical(path_,ec);
|
|
if(ec)
|
|
return {};
|
|
|
|
rv = fs::lstat(can_path,&initial_st);
|
|
if(rv == -1)
|
|
return {};
|
|
|
|
tmp_path = can_path;
|
|
while(tmp_path != tmp_path.root_path())
|
|
{
|
|
rv = fs::lstat(tmp_path.parent_path(),&tmp_st);
|
|
if(rv == -1)
|
|
return {};
|
|
if(tmp_st.st_dev != initial_st.st_dev)
|
|
return tmp_path;
|
|
|
|
tmp_path = tmp_path.parent_path();
|
|
}
|
|
|
|
return tmp_path;
|
|
}
|