[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [baloo] src: Balooshow: Allow us to lookup files by their inode + devId
From:       Vishesh Handa <me () vhanda ! in>
Date:       2015-10-10 16:52:57
Message-ID: E1ZkxOD-0000RL-02 () scm ! kde ! org
[Download RAW message or body]

Git commit 3b901d18fdf1b4c2e5245f0752a0a509585308e1 by Vishesh Handa.
Committed on 10/10/2015 at 16:52.
Pushed by vhanda into branch 'master'.

Balooshow: Allow us to lookup files by their inode + devId

Internally we store the file id as devId + inode. We may as well allow
users to lookup based on these parameters. It can be useful.

M  +11   -5    src/engine/idutils.h
M  +15   -1    src/tools/balooshow/main.cpp

http://commits.kde.org/baloo/3b901d18fdf1b4c2e5245f0752a0a509585308e1

diff --git a/src/engine/idutils.h b/src/engine/idutils.h
index c03494f..7c4f898 100644
--- a/src/engine/idutils.h
+++ b/src/engine/idutils.h
@@ -28,6 +28,15 @@
 
 namespace Baloo {
 
+inline quint64 devIdAndInodeToId(quint32 devId, quint32 inode)
+{
+    quint32 arr[2];
+    arr[0] = devId;
+    arr[1] = inode;
+
+    return *(reinterpret_cast<quint64*>(arr));
+}
+
 /**
  * Convert the QT_STATBUF into a 64 bit unique identifier for the file.
  * This identifier is combination of the device id and inode number.
@@ -36,11 +45,8 @@ inline quint64 statBufToId(const QT_STATBUF& stBuf)
 {
     // We're loosing 32 bits of info, so this could potentially break
     // on file systems with really large inode and device ids
-    quint32 arr[2];
-    arr[0] = static_cast<quint32>(stBuf.st_dev);
-    arr[1] = static_cast<quint32>(stBuf.st_ino);
-
-    return *(reinterpret_cast<quint64*>(arr));
+    return devIdAndInodeToId(static_cast<quint32>(stBuf.st_dev),
+                             static_cast<quint32>(stBuf.st_ino));
 }
 
 inline quint64 filePathToId(const QByteArray& filePath)
diff --git a/src/tools/balooshow/main.cpp b/src/tools/balooshow/main.cpp
index 3aa03bb..6dfcc1d 100644
--- a/src/tools/balooshow/main.cpp
+++ b/src/tools/balooshow/main.cpp
@@ -67,6 +67,10 @@ int main(int argc, char* argv[])
     parser.addPositionalArgument(QLatin1String("files"), QLatin1String("The file \
                urls"));
     parser.addOption(QCommandLineOption(QStringList() << QLatin1String("x"),
                                         QLatin1String("Print internal info")));
+    parser.addOption(QCommandLineOption(QStringList() << QLatin1String("i"),
+                                        QLatin1String("Inode number of the fiel to \
show"))); +    parser.addOption(QCommandLineOption(QStringList() << \
QLatin1String("d"), +                                        QLatin1String("Device id \
for the files"), QLatin1String("deviceId"), QString()));  parser.addHelpOption();
     parser.process(app);
 
@@ -85,7 +89,11 @@ int main(int argc, char* argv[])
         if (QFile::exists(url)) {
             urls.append(url);
         } else {
-            urls.append(QLatin1String("file:") + arg);
+            if (parser.isSet("i")) {
+                urls.append(QLatin1String("inode:") + arg);
+            } else {
+                urls.append(QLatin1String("file:") + arg);
+            }
         }
     }
 
@@ -117,6 +125,12 @@ int main(int argc, char* argv[])
                 stream << "GivenINode: " << Baloo::idToInode(fid) << " ActualINode: \
                " << Baloo::idToInode(actualFid) << "\n";
                 stream << "GivenDeviceID: " << Baloo::idToDeviceId(fid) << " \
ActualDeviceID: " << Baloo::idToDeviceId(actualFid) << "\n";  }
+        } else if (url.startsWith(QStringLiteral("inode:"))) {
+            quint32 inode = url.mid(6).toULong();
+            quint32 devId = parser.value("d").toULong();
+
+            fid = Baloo::devIdAndInodeToId(devId, inode);
+            url = QFile::decodeName(tr.documentUrl(fid));
         } else {
             fid = Baloo::filePathToId(QFile::encodeName(url));
         }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic