[RTEMS Project] #2413: Untar_FromMemory breaks on create directory if they exists, even on root one.
RTEMS trac
trac at rtems.org
Mon Sep 7 09:13:15 UTC 2015
#2413: Untar_FromMemory breaks on create directory if they exists, even on root
one.
---------------------+-------------------
Reporter: ppisa | Owner:
Type: defect | Status: new
Priority: normal | Milestone: 4.11
Component: General | Version: 4.11
Severity: normal | Resolution:
Keywords: |
---------------------+-------------------
Comment (by ppisa):
Simple workaround is to ignore EEXIST for directory create (mkdir).
{{{
diff --git a/cpukit/libmisc/untar/untar.c b/cpukit/libmisc/untar/untar.c
index aed8fed..4acb4dc 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,8 @@ Untar_FromMemory(
}
} else if (linkflag == DIRTYPE) {
if ( mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO) != 0 ) {
+ if (errno == EEXIST)
+ continue;
printk("Untar: failed to create directory %s\n", fname);
retval = UNTAR_FAIL;
break;
(
}}}
Alternative providing more strict checking with stat call
{{{
diff --git a/cpukit/libmisc/untar/untar.c b/cpukit/libmisc/untar/untar.c
index aed8fed..4591a8b 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,13 @@ 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;
+ }
+ }
printk("Untar: failed to create directory %s\n", fname);
retval = UNTAR_FAIL;
break;
}}}
--
Ticket URL: <http://devel.rtems.org/ticket/2413#comment:1>
RTEMS Project <http://www.rtems.org/>
RTEMS Project
More information about the bugs
mailing list