comparison scripts/miscellaneous/unpack.m @ 20326:2fc43288a6c4 stable

unpack.m: Stop hang when unpacking on to existing filename (bug #45331). * unpack.m: Follow documentation and use current directory for unpacking if no output directory is specified. Call tilde_expand() on any user-supplied directory in case it contains '~'. Add -f(orce) flag to gzip and bzip unpack commands so that any file will be overwritten and Octave will not hang waiting for user input. Strip trailing file separator from output directory so that a proper comparison is made to beginning directory which never includes the file separator.
author Rik <rik@octave.org>
date Wed, 01 Jul 2015 14:14:49 -0700
parents df437a52bcaf
children
comparison
equal deleted inserted replaced
20315:077e73619ba8 20326:2fc43288a6c4
143 endif 143 endif
144 144
145 endif 145 endif
146 146
147 file = make_absolute_filename (file); 147 file = make_absolute_filename (file);
148
149 if (isempty (dir))
150 dir = ".";
151 else
152 dir = tilde_expand (dir);
153 endif
148 154
149 ## Instructions on what to do for any extension. 155 ## Instructions on what to do for any extension.
150 ## 156 ##
151 ## The field names are the file extension without periods. 157 ## The field names are the file extension without periods.
152 ## The first cell is what is executed to unpack an archive verbosely. 158 ## The first cell is what is executed to unpack an archive verbosely.
155 ## The fourth cell indicates if the files may need to be manually moved 161 ## The fourth cell indicates if the files may need to be manually moved
156 ## (i.e., tar and unzip decompress into the current directory while 162 ## (i.e., tar and unzip decompress into the current directory while
157 ## bzip2 and gzip decompress the file at its location). 163 ## bzip2 and gzip decompress the file at its location).
158 persistent commandlist; 164 persistent commandlist;
159 if (isempty (commandlist)) 165 if (isempty (commandlist))
160 commandlist.gz = {'gzip -d -v -r "%s"', ... 166 commandlist.gz = {'gzip -d -v -f -r "%s"', ...
161 'gzip -d -r "%s"', ... 167 'gzip -d -f -r "%s"', ...
162 @__parse_gzip__, true}; 168 @__parse_gzip__, true};
163 commandlist.z = commandlist.gz; 169 commandlist.z = commandlist.gz;
164 commandlist.bz2 = {'bzip2 -d -v "%s"', ... 170 commandlist.bz2 = {'bzip2 -d -v -f "%s"', ...
165 'bzip2 -d "%s"', ... 171 'bzip2 -d -f "%s"', ...
166 @__parse_bzip2__, true}; 172 @__parse_bzip2__, true};
167 commandlist.bz = commandlist.bz2; 173 commandlist.bz = commandlist.bz2;
168 commandlist.tar = {'tar xvf "%s"', ... 174 commandlist.tar = {'tar xvf "%s"', ...
169 'tar xf "%s"', ... 175 'tar xf "%s"', ...
170 @__parse_tar__, false}; 176 @__parse_tar__, false};
203 else 209 else
204 startdir = origdir; 210 startdir = origdir;
205 endif 211 endif
206 cstartdir = make_absolute_filename (startdir); 212 cstartdir = make_absolute_filename (startdir);
207 cenddir = make_absolute_filename (dir); 213 cenddir = make_absolute_filename (dir);
214 if (cenddir(end) == filesep)
215 cenddir(end) = [];
216 endif
208 needmove = move && ! strcmp (cstartdir, cenddir); 217 needmove = move && ! strcmp (cstartdir, cenddir);
209 if (nargout > 0 || needmove) 218 if (nargout > 0 || needmove)
210 command = commandv; 219 command = commandv;
211 else 220 else
212 command = commandq; 221 command = commandq;