From 8d54d01f09760c78d649baed0b88aa0f80069de7 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 15 Nov 2017 14:38:01 -0500 Subject: Add a bunch of ZFS information routines to LFileInfo. Also utilize this ZFS info in lumina-fileinfo (if appropriate) --- src-qt5/core/libLumina/LFileInfo.cpp | 73 ++++++++++++++++++++++++++++++++++++ src-qt5/core/libLumina/LFileInfo.h | 13 ++++++- 2 files changed, 85 insertions(+), 1 deletion(-) (limited to 'src-qt5/core/libLumina') diff --git a/src-qt5/core/libLumina/LFileInfo.cpp b/src-qt5/core/libLumina/LFileInfo.cpp index e54ce5cc..e7d2b71a 100644 --- a/src-qt5/core/libLumina/LFileInfo.cpp +++ b/src-qt5/core/libLumina/LFileInfo.cpp @@ -60,6 +60,31 @@ void LFileInfo::loadExtraInfo(){ } } +bool LFileInfo::zfsAvailable(){ + static unsigned int avail = 2; + if(avail == 2){ avail = (LUtils::isValidBinary("zfs") ? 0 : 1); } + return (avail == 0); +} + +void LFileInfo::getZfsDataset(){ + if(zfs_ds.isEmpty()){ + //First run - need to probe the current directory + bool ok = false; + //Use the "atime" property for this check - been around since the earliest versions of ZFS and should take no time to probe + QString out = LUtils::runCommand(ok, "zfs", QStringList() << "get" << "-H" << "atime" << this->canonicalFilePath() ); + if(!ok){ zfs_ds = "."; } //just something that is not empty - but is clearly not a valid dataset + else{ zfs_ds = out.section("\n",0,0).section("\t",0,0).simplified(); } + //qDebug() << "Found Dataset:" << zfs_ds << out << ok; + } +} + +bool LFileInfo::goodZfsDataset(){ + if(!zfsAvailable()){ return false; } + getZfsDataset(); //ensure this field is populated + if(zfs_ds=="." || zfs_ds.isEmpty()){ return false; } + return true; +} + //Functions for accessing the extra information // -- Return the mimetype for the file QString LFileInfo::mimetype(){ @@ -109,3 +134,51 @@ bool LFileInfo::isImage(){ bool LFileInfo::isAVFile(){ return (mime.startsWith("audio/") || mime.startsWith("video/") ); } + +bool LFileInfo::isZfsDataset(){ + if(!goodZfsDataset()){ return false; } + return ( ("/"+zfs_ds.section("/",1,-1)) == this->canonicalFilePath()); +} + +QString LFileInfo::zfsPool(){ + if(!goodZfsDataset()){ return ""; } + return zfs_ds.section("/",0,0); +} + +QStringList LFileInfo::zfsSnapshots(){ + if(!goodZfsDataset()){ return QStringList(); } + QString relpath = this->canonicalFilePath().remove(0, QString("/"+zfs_ds.section("/",1,-1)).length() ); + //qDebug() << "Got Relative path:" << zfs_ds << this->canonicalFilePath() << relpath; + QDir dir("/"+zfs_ds.section("/",1,-1)+"/.zfs/snapshot/"); + QStringList snaps = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Time); + for(int i=0; i LFileInfoList; -- cgit