diff options
Diffstat (limited to 'cpukit/libmisc')
-rw-r--r-- | cpukit/libmisc/untar/untar.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/cpukit/libmisc/untar/untar.c b/cpukit/libmisc/untar/untar.c index aed8fed356..e4b0aeb968 100644 --- a/cpukit/libmisc/untar/untar.c +++ b/cpukit/libmisc/untar/untar.c @@ -28,6 +28,7 @@ #include <string.h> #include <stdlib.h> #include <unistd.h> +#include <errno.h> #include <sys/stat.h> #include <fcntl.h> #include <rtems/untar.h> @@ -203,6 +204,19 @@ Untar_FromMemory( } } else if (linkflag == DIRTYPE) { if ( mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO) != 0 ) { + if (errno == EEXIST) { + struct stat stat_buf; + if ( stat(fname, &stat_buf) == 0 ) { + if ( S_ISDIR(stat_buf.st_mode) ) { + continue; + } else { + if ( unlink(fname) != -1 ) { + if ( mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO) == 0 ) + continue; + } + } + } + } printk("Untar: failed to create directory %s\n", fname); retval = UNTAR_FAIL; break; @@ -319,7 +333,21 @@ Untar_FromFile( close(out_fd); } } else if (linkflag == DIRTYPE) { - (void) mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO); + if ( mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO) != 0 ) { + if (errno == EEXIST) { + struct stat stat_buf; + if ( stat(fname, &stat_buf) == 0 ) { + if ( S_ISDIR(stat_buf.st_mode) ) { + continue; + } else { + if ( unlink(fname) != -1 ) { + if ( mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO) == 0 ) + continue; + } + } + } + } + } } } free(bufr); |