dir listing not starting with . and ..

Søren Hauberg soren at hauberg.org
Wed Feb 4 14:44:03 CST 2009


ons, 04 02 2009 kl. 12:31 -0500, skrev John W. Eaton:
> I would still recommend creating the temporary directory to work in,
> but instead of taking the third element of the directory listing, I
> would look for the expected package directory.
> 
> Picking the third element of readdir seems fragile to me, so using a
> name derived from the package file name might be more robust.  If
> someone renames a package file and tries to install it, then you could
> just issue a message saying that the package appears corrupted because
> it did not extract into the expected directory structure.
> 
> I know that people are not supposed to unpack the package files by
> hand to install them, but some people might want to unpack them
> anyway, without installing, just to see what they contain.  So I think
> the packages should unpack into directories with names that include
> the version number.  I really dislike unpacking a tar file and having
> it go into some directory that isn't the same as the name of the tar
> file minus the ".tar.gz" extension.  With the version number included,
> I can easily unpack two or more versions of the same package in a
> single directory and compare them, for example.  If the version
> information is stripped, then that becomes more of a hassle.  Is there
> some good reason not to keep the version info?  Does it create some
> difficult problem for the pkg functions?

The problem is that we cannot use 'fileparts' for files with a '.tar.gz'
extension:

  octave:9> [d, f, e] = fileparts ("foo.tar.gz")
  d = 
  f = foo.tar
  e = .gz

So, we have to hardcode '.tar.gz' in 'pkg'. The attached changeset
essentially does this.

Søren

2009-02-04  Soren Hauberg  <hauberg at gmail.com>

        * pkg/pkg.m: Attempt to find the best matching uncompressed
        directory during installation.

-------------- next part --------------
# HG changeset patch
# User Soren Hauberg <hauberg at gmail.com>
# Date 1233780069 -3600
# Node ID d2fb495377c76e85006534a1784c4932cced4382
# Parent  33783e94fb16957d69fa52b1c02c56fc3c294392
scripts/pkg/pkg.m: attempt to find the best matching uncompressed directory during installation

diff -r 33783e94fb16 -r d2fb495377c7 scripts/pkg/pkg.m
--- a/scripts/pkg/pkg.m	Wed Feb 04 13:28:06 2009 -0500
+++ b/scripts/pkg/pkg.m	Wed Feb 04 21:41:09 2009 +0100
@@ -610,11 +610,24 @@
       endif
 
       if (exist (tgz, "file") || exist (tgz, "dir"))
-	## The two first entries of dirlist are "." and "..".
+        ## Extract package name from file name
+        [not_used, name_from_file] = fileparts (tgz);
+        if (strcmpi (name_from_file (end-3:end), ".tar"))
+          name_from_file (end-3:end) = [];
+        endif
+        
+	## Find the directory that best matches the package file name
+	dir_list_idx = strmatch (name_from_file, dirlist);
+	if (isempty (dir_list_idx))
+	  dir_list_idx = length (dirlist);
+          warning (["pkg: the package appears corrupt as it did not extract into ", \
+                    "the expected directory structure"]);
+	endif
+	
 	if (exist (tgz, "file"))
-	  packdir = fullfile (tmpdir, dirlist{3});
+	  packdir = fullfile (tmpdir, dirlist {dir_list_idx});
 	else
-	  packdir = fullfile (pwd(), dirlist{3});
+	  packdir = fullfile (pwd(), dirlist {dir_list_idx});
 	endif
 	packdirs{end+1} = packdir;
 	


More information about the Bug-octave mailing list