Changeset a6d176f in rtems


Ignore:
Timestamp:
Nov 23, 2015, 9:09:06 AM (4 years ago)
Author:
Pavel Pisa <pisa@…>
Branches:
4.11
Children:
7828f1c3
Parents:
f8bbbdd
git-author:
Pavel Pisa <pisa@…> (11/23/15 09:09:06)
git-committer:
Gedare Bloom <gedare@…> (11/23/15 15:40:06)
Message:

untar: do not exit with error when created directory already exists.

The problem exists for both RTEMS untar implementations and their
variants: Untar_FromMemory(), Untar_FromFile() and rtems_tarfs_load().

If filesystem object already exists at extracted directory path
then if it is directory, creation is ignored. Attempt
to delete/unlink object and make directory is tried for other cases.

This simple approach problem reported in ticket fixes #2413.
Behavior follows GNU tar and BSD tar practice for directories
but much more work is required to achieve full semantics
of the full featured tar implementation still.

Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libfs/src/imfs/imfs_load_tar.c

    rf8bbbdd ra6d176f  
    104104      ++len;
    105105      strncat(full_filename, filename, 256-len-1);
    106       rv = mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO);
     106      if ( mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO) != 0 ) {
     107        if (errno == EEXIST) {
     108          struct stat stat_buf;
     109          if ( stat(full_filename, &stat_buf) == 0 ) {
     110            if (  S_ISDIR(stat_buf.st_mode) ) {
     111              continue;
     112            } else {
     113              if ( unlink(full_filename) != -1 ) {
     114                if ( mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO) == 0 )
     115                  continue;
     116              }
     117            }
     118          }
     119        }
     120        rv = -1;
     121      }
    107122    }
     123
    108124    /*
    109125     * Create a LINEAR_FILE node
  • cpukit/libmisc/untar/untar.c

    rf8bbbdd ra6d176f  
    2929#include <stdlib.h>
    3030#include <unistd.h>
     31#include <errno.h>
    3132#include <sys/stat.h>
    3233#include <fcntl.h>
     
    204205    } else if (linkflag == DIRTYPE) {
    205206      if ( mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO) != 0 ) {
     207        if (errno == EEXIST) {
     208          struct stat stat_buf;
     209          if ( stat(fname, &stat_buf) == 0 ) {
     210            if (  S_ISDIR(stat_buf.st_mode) ) {
     211              continue;
     212            } else {
     213              if ( unlink(fname) != -1 ) {
     214                if ( mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO) == 0 )
     215                  continue;
     216              }
     217            }
     218          }
     219        }
    206220        printk("Untar: failed to create directory %s\n", fname);
    207221        retval = UNTAR_FAIL;
     
    320334      }
    321335    } else if (linkflag == DIRTYPE) {
    322       (void) mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO);
     336      if ( mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO) != 0 ) {
     337        if (errno == EEXIST) {
     338          struct stat stat_buf;
     339          if ( stat(fname, &stat_buf) == 0 ) {
     340            if (  S_ISDIR(stat_buf.st_mode) ) {
     341              continue;
     342            } else {
     343              if ( unlink(fname) != -1 ) {
     344                if ( mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO) == 0 )
     345                  continue;
     346              }
     347            }
     348          }
     349        }
     350      }
    323351    }
    324352  }
Note: See TracChangeset for help on using the changeset viewer.