Previous 15994 Revisions Next

r3108 Thursday 28th August, 2008 at 01:58:12 UTC by Nathan Woods
Fixed a file manager bug that could cause the working directory to be lost when
inside ZIP files.
[docs]messnew.txt
[src/mess]zippath.c

src/mess/zippath.c
r3107r3108
203203
204204
205205/*-------------------------------------------------
206    next_path_char - lexes out the next path
207   character, normalizing separators as '/'
208-------------------------------------------------*/
209
210static char next_path_char(const char *s, int *pos)
211{
212   char result;
213
214   /* skip over any initial separators */
215   if (*pos == 0)
216   {
217      while(is_zip_file_separator(s[*pos]))
218         (*pos)++;
219   }
220
221   /* are we at a path separator? */
222   if (is_zip_file_separator(s[*pos]))
223   {
224      /* skip over path separators */
225      while(is_zip_file_separator(s[*pos]))
226         (*pos)++;
227
228      /* normalize as '/' */
229      result = '/';
230   }
231   else if (s[*pos] != '\0')
232   {
233      /* return character */
234      result = tolower(s[(*pos)++]);
235   }
236   else
237   {
238      /* return NUL */
239      result = '\0';
240   }
241   return result;
242}
243
244
245
246
247/*-------------------------------------------------
206248    zippath_find_sub_path - attempts to identify the
207249   type of a sub path in a zip file
208250-------------------------------------------------*/
r3107r3108
210252const zip_file_header *zippath_find_sub_path(zip_file *zipfile, const char *subpath, osd_dir_entry_type *type)
211253{
212254   int i, j;
255   char c1, c2, last_char;
213256   const zip_file_header *header;
214257
215258   for (header = zip_file_first_file(zipfile); header != NULL; header = zip_file_next_file(zipfile))
r3107r3108
224267
225268      i = 0;
226269      j = 0;
227      do
228      {
229         while(is_zip_file_separator(header->filename[i]))
230            i++;
231         while(is_zip_path_separator(subpath[j]))
232            j++;
233         while((header->filename[i] != '\0') && (tolower(header->filename[i]) == tolower(subpath[j])))
234         {
235            i++;
236            j++;
237         }
238      }
239      while(is_zip_file_separator(header->filename[i]) && is_zip_path_separator(subpath[j]));
270      last_char = '/';
271      while((c1 = next_path_char(header->filename, &i)) == (c2 = next_path_char(subpath, &j)))
272         last_char = c2;
240273
241      if (subpath[j] == '\0')
274      if (c2 == '\0')
242275      {
243         if (header->filename[i] == '\0')
276         if (c1 == '\0')
244277         {
245278            if (type != NULL)
246279               *type = ENTTYPE_FILE;
247280            return header;
248281         }
249         else if ((i == 0) || is_zip_file_separator(header->filename[i]))
282         else if ((last_char == '/') || (c1 == '/'))
250283         {
251284            if (type != NULL)
252285               *type = ENTTYPE_DIR;
r3107r3108
325358   if ((current_entry_type == ENTTYPE_FILE) && is_zip_file(astring_c(apath_trimmed))
326359      && (zip_file_open(astring_c(apath_trimmed), zipfile) == ZIPERR_NONE))
327360   {
361      i = strlen(path + astring_len(apath));
362      while((i > 0) && is_zip_path_separator(path[astring_len(apath) + i - 1]))
363         i--;
364      astring_cpych(newpath, path + astring_len(apath), i);
365
328366      /* this was a true ZIP path - attempt to identify the type of path */
329      zippath_find_sub_path(*zipfile, path + astring_len(apath), &current_entry_type);
367      zippath_find_sub_path(*zipfile, astring_c(newpath), &current_entry_type);
330368      if (current_entry_type == ENTTYPE_NONE)
331369      {
332370         err = FILERR_NOT_FOUND;
333371         goto done;
334372      }
335      astring_cpyc(newpath, path + astring_len(apath));
336373   }
337374   else
338375   {
docs/messnew.txt
r3107r3108
1414
1515User Interface Changes:
1616-----------------------
17(none)
17- Fixed a file manager bug that could cause the working directory to be lost
18  when inside ZIP files.  [Nate Woods]
1819
1920
2021

Previous 15994 Revisions Next


© 1998-2018 The MESS Team