mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-07-02 14:04:22 +00:00
Implement label and uuid retrieval for the disk being scanned.
This commit is contained in:
parent
29c98c0154
commit
742d024bfb
3 changed files with 57 additions and 1 deletions
|
@ -57,7 +57,7 @@ if ("${DINDEXER_CONFIG_FILE}" STREQUAL "")
|
|||
endif()
|
||||
message(STATUS "Config file set to \"${DINDEXER_CONFIG_FILE}\"")
|
||||
|
||||
find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options)
|
||||
find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options filesystem)
|
||||
find_package(PostgreSQL 8.3 REQUIRED)
|
||||
find_package(YamlCpp 0.5.1 REQUIRED)
|
||||
import_libpqtypes_project("${PostgreSQL_INCLUDE_DIRS}" "-O3 ${march_flag}")
|
||||
|
|
|
@ -35,6 +35,10 @@
|
|||
# include <iostream>
|
||||
#endif
|
||||
#include <cstdint>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace mchlib {
|
||||
namespace {
|
||||
|
@ -167,6 +171,41 @@ namespace mchlib {
|
|||
return static_cast<LinuxDeviceTypes>(retval);
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string find_with_same_inode (const std::string& parWhat, const char* parWhere) {
|
||||
using boost::make_iterator_range;
|
||||
|
||||
struct stat st;
|
||||
if (stat(parWhat.c_str(), &st))
|
||||
return std::string();
|
||||
|
||||
const auto& inode = st.st_ino;
|
||||
|
||||
fs::path p(parWhere);
|
||||
if (not fs::exists(p) or not fs::is_directory(p)) {
|
||||
throw std::runtime_error(
|
||||
std::string("Search path \"") + p.string() +
|
||||
"\" doesn't exist");
|
||||
}
|
||||
|
||||
for (const fs::directory_entry& itm : make_iterator_range(fs::directory_iterator(p), fs::directory_iterator())) {
|
||||
struct stat curr_st;
|
||||
if (stat(itm.path().c_str(), &curr_st) and inode == curr_st.st_ino)
|
||||
return fs::basename(itm);
|
||||
}
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
//Get disc label by doing the equivalent of:
|
||||
//find -L /dev/disk/by-label -inum $(stat -c %i /dev/sda1) -print
|
||||
std::string retrieve_label (const std::string& parMountpoint) {
|
||||
return find_with_same_inode(parMountpoint, "/dev/disk/by-label");
|
||||
}
|
||||
|
||||
std::string retrieve_uuid (const std::string& parMountpoint) {
|
||||
return find_with_same_inode(parMountpoint, "/dev/disk/by-uuid");
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
DiscInfo::DiscInfo (std::string&& parPath) :
|
||||
|
@ -187,6 +226,11 @@ namespace mchlib {
|
|||
}
|
||||
input_path.pop_right();
|
||||
} while(input_path.atom_count() > 0);
|
||||
|
||||
if (mountpoint_found()) {
|
||||
m_label = retrieve_label(mountpoint());
|
||||
m_uuid = retrieve_uuid(mountpoint());
|
||||
}
|
||||
}
|
||||
|
||||
bool DiscInfo::mountpoint_found() const {
|
||||
|
@ -329,4 +373,12 @@ namespace mchlib {
|
|||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
const std::string& DiscInfo::label() const {
|
||||
return m_label;
|
||||
}
|
||||
|
||||
const std::string& DiscInfo::filesystem_uuid() const {
|
||||
return m_uuid;
|
||||
}
|
||||
} //namespace mchlib
|
||||
|
|
|
@ -52,11 +52,15 @@ namespace mchlib {
|
|||
OpticalTypes optical_type ( void ) const;
|
||||
DriveTypes drive_type ( void ) const;
|
||||
#endif
|
||||
const std::string& label ( void ) const;
|
||||
const std::string& filesystem_uuid ( void ) const;
|
||||
|
||||
private:
|
||||
const std::string m_initial_path;
|
||||
std::string m_mountpoint;
|
||||
std::string m_device;
|
||||
std::string m_label;
|
||||
std::string m_uuid;
|
||||
};
|
||||
} //namespace mchlib
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue