Patch for kdeaddons .lnk kfile-plugin

Ben Burton bab at debian.org
Sat Oct 23 10:40:09 BST 2004


Hi,

In packaging kdeaddons for debian, I discovered that the .lnk plugin
(kdeaddons/kfile-plugins) was broken.

Specifically, it would read in path information from a .lnk file such as:

  C:\foo\bar.txt

and split it up as follows:

  info.driveName = C:\foo\bar.txt
  info.path =

The result is (i) that the file information is badly formatted (a trailing
slash is appended), but more seriously (ii) that the lnkforward mechanism
breaks completely.  The lnkforward mechanism splits off the first letter
of the drive and tosses the rest away, and thus tries to open:

  /mount-point/

instead of:

  /mount-point/foo/bar.txt

Attached is a patch that I believe resolves this problem.  Specifically,
it looks to see whether start+loc.basePath (which was previously
used for the drive and nothing else) contains any path information, and
if so prepends it to start+loc.pathname (which was previously used for
the path) to obtain the final path.

There are still other issues (e.g,. if the pathname in the .lnk file is
relative), but these issues are also present in the current code.  That
is, whilst this patch does not make the plugin perfect, I don't believe
it breaks anything.

Does it look okay?  Should it be committed?

Note that the patch is against BRANCH, not HEAD.

(CCing the lnk plugin author also.)

Ben.


Index: kfile-plugins/lnk/kfile_lnk.cpp
===================================================================
RCS file: /home/kde/kdeaddons/kfile-plugins/lnk/kfile_lnk.cpp,v
retrieving revision 1.3
diff -u -3 -p -r1.3 kfile_lnk.cpp
--- kfile-plugins/lnk/kfile_lnk.cpp	28 Jun 2004 12:09:54 -0000	1.3
+++ kfile-plugins/lnk/kfile_lnk.cpp	23 Oct 2004 08:43:10 -0000
@@ -76,7 +76,7 @@ bool lnkPlugin::readInfo( KFileMetaInfo&
   if ( ! lnkInfo.isNetworkPath )
   {
     appendItem(group, "Where", i18n("on Windows disk: %1").arg(lnkInfo.volumeName));  // volume label
-    appendItem(group, "PointsTo", QString("%1\\%2").arg(lnkInfo.driveName).arg(lnkInfo.path));
+    appendItem(group, "PointsTo", QString("%1%2").arg(lnkInfo.driveName).arg(lnkInfo.path));
   }
   else
   {
Index: kfile-plugins/lnk/read_lnk.cpp
===================================================================
RCS file: /home/kde/kdeaddons/kfile-plugins/lnk/read_lnk.cpp,v
retrieving revision 1.2
diff -u -3 -p -r1.2 read_lnk.cpp
--- kfile-plugins/lnk/read_lnk.cpp	6 Jun 2004 17:05:21 -0000	1.2
+++ kfile-plugins/lnk/read_lnk.cpp	23 Oct 2004 08:43:10 -0000
@@ -156,10 +156,28 @@ bool readLNK(const KURL &url, LNKInfo &i
     {
       info.volumeName = (start + loc.localVolume + 0x10);  // volume label
 
-      info.driveName = (start + loc.basePath);
+      info.path = QString::null;
+
+      if ( *(start + loc.basePath) )
+      {
+        // Don't put any more than "X:" into info.driveName.
+        info.driveName = *(start + loc.basePath);
+        info.driveName += ':';
+
+        // If we in fact do have more than just "X:", store any additional
+        // path information separately in info.path.
+        if ( *(start + loc.basePath + 1) == ':' &&
+             *(start + loc.basePath + 2) != 0)
+          info.path = (start + loc.basePath + 2);
+      }
 
       if ( *(start + loc.pathname) != 0 )
-        info.path = (start + loc.pathname);
+      {
+        if ( info.path.isNull() )
+          info.path = (start + loc.pathname);
+        else
+          info.path = info.path + "\\" + (start + loc.pathname);
+      }
     }
     else  // network path
     {





More information about the kde-core-devel mailing list