Re: [PATCH v2] untar: do not exit with error when created directory already exists (fixes #2413).

2015-09-10 Thread Pavel Pisa
Hello Gedare and others,

On Thursday 10 of September 2015 05:00:27 Gedare Bloom wrote:
> Looks good. This should go on 4.11 and master? Someone can commit.

please commit to both.

> On Wed, Sep 9, 2015 at 6:09 PM, Pavel Pisa  wrote:
> > The problem exists for both RTEMS untar implementations and their
> > variants: Untar_FromMemory(), Untar_FromFile() and rtems_tarfs_load().

It is interresting that problem has not been catch by tests.
But if tar is only for some nonexistent subdirectory, i.e.

  /data

or rtems_tarfs_load() specifies subdiretory then problem
does not pop-up.

But if the tar is complete filesystem and contains

  ./
  ./data
  ./bin

or 

  /
  /data
  /bin

then all these functions fails at start of the archive.

Best wishes,

 Pavel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH v2] untar: do not exit with error when created directory already exists (fixes #2413).

2015-09-10 Thread Gedare Bloom
Do you have a test you can contribute?

On Thu, Sep 10, 2015 at 3:56 AM, Pavel Pisa  wrote:
> Hello Gedare and others,
>
> On Thursday 10 of September 2015 05:00:27 Gedare Bloom wrote:
>> Looks good. This should go on 4.11 and master? Someone can commit.
>
> please commit to both.
>
>> On Wed, Sep 9, 2015 at 6:09 PM, Pavel Pisa  wrote:
>> > The problem exists for both RTEMS untar implementations and their
>> > variants: Untar_FromMemory(), Untar_FromFile() and rtems_tarfs_load().
>
> It is interresting that problem has not been catch by tests.
> But if tar is only for some nonexistent subdirectory, i.e.
>
>   /data
>
> or rtems_tarfs_load() specifies subdiretory then problem
> does not pop-up.
>
> But if the tar is complete filesystem and contains
>
>   ./
>   ./data
>   ./bin
>
> or
>
>   /
>   /data
>   /bin
>
> then all these functions fails at start of the archive.
>
> Best wishes,
>
>  Pavel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v2] untar: do not exit with error when created directory already exists (fixes #2413).

2015-09-09 Thread Pavel Pisa
The problem exists for both RTEMS untar implementations and their
variants: Untar_FromMemory(), Untar_FromFile() and rtems_tarfs_load().
---
 cpukit/libfs/src/imfs/imfs_load_tar.c | 12 +++-
 cpukit/libmisc/untar/untar.c  | 18 +-
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/cpukit/libfs/src/imfs/imfs_load_tar.c 
b/cpukit/libfs/src/imfs/imfs_load_tar.c
index 7228978..2d4ca6b 100644
--- a/cpukit/libfs/src/imfs/imfs_load_tar.c
+++ b/cpukit/libfs/src/imfs/imfs_load_tar.c
@@ -103,8 +103,18 @@ int rtems_tarfs_load(
 strcat(full_filename, "/");
   ++len;
   strncat(full_filename, filename, 256-len-1);
-  rv = mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO);
+  if ( mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO) != 0 ) {
+if (errno == EEXIST) {
+  struct stat stat_buf;
+  if ( stat(full_filename, _buf) == 0 ) {
+if (  S_ISDIR(stat_buf.st_mode) )
+  continue;
+  }
+}
+rv = -1;
+  }
 }
+
 /*
  * Create a LINEAR_FILE node
  */
diff --git a/cpukit/libmisc/untar/untar.c b/cpukit/libmisc/untar/untar.c
index aed8fed..2c1e304 100644
--- a/cpukit/libmisc/untar/untar.c
+++ b/cpukit/libmisc/untar/untar.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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, _buf) == 0 ) {
+if (  S_ISDIR(stat_buf.st_mode) )
+  continue;
+  }
+}
 printk("Untar: failed to create directory %s\n", fname);
 retval = UNTAR_FAIL;
 break;
@@ -319,7 +327,15 @@ 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, _buf) == 0 ) {
+if (  S_ISDIR(stat_buf.st_mode) )
+  continue;
+  }
+}
+  }
 }
   }
   free(bufr);
-- 
1.9.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH v2] untar: do not exit with error when created directory already exists (fixes #2413).

2015-09-09 Thread Gedare Bloom
Looks good. This should go on 4.11 and master? Someone can commit.

On Wed, Sep 9, 2015 at 6:09 PM, Pavel Pisa  wrote:
> The problem exists for both RTEMS untar implementations and their
> variants: Untar_FromMemory(), Untar_FromFile() and rtems_tarfs_load().
> ---
>  cpukit/libfs/src/imfs/imfs_load_tar.c | 12 +++-
>  cpukit/libmisc/untar/untar.c  | 18 +-
>  2 files changed, 28 insertions(+), 2 deletions(-)
>
> diff --git a/cpukit/libfs/src/imfs/imfs_load_tar.c 
> b/cpukit/libfs/src/imfs/imfs_load_tar.c
> index 7228978..2d4ca6b 100644
> --- a/cpukit/libfs/src/imfs/imfs_load_tar.c
> +++ b/cpukit/libfs/src/imfs/imfs_load_tar.c
> @@ -103,8 +103,18 @@ int rtems_tarfs_load(
>  strcat(full_filename, "/");
>++len;
>strncat(full_filename, filename, 256-len-1);
> -  rv = mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO);
> +  if ( mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO) != 0 ) {
> +if (errno == EEXIST) {
> +  struct stat stat_buf;
> +  if ( stat(full_filename, _buf) == 0 ) {
> +if (  S_ISDIR(stat_buf.st_mode) )
> +  continue;
> +  }
> +}
> +rv = -1;
> +  }
>  }
> +
>  /*
>   * Create a LINEAR_FILE node
>   */
> diff --git a/cpukit/libmisc/untar/untar.c b/cpukit/libmisc/untar/untar.c
> index aed8fed..2c1e304 100644
> --- a/cpukit/libmisc/untar/untar.c
> +++ b/cpukit/libmisc/untar/untar.c
> @@ -28,6 +28,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -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, _buf) == 0 ) {
> +if (  S_ISDIR(stat_buf.st_mode) )
> +  continue;
> +  }
> +}
>  printk("Untar: failed to create directory %s\n", fname);
>  retval = UNTAR_FAIL;
>  break;
> @@ -319,7 +327,15 @@ 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, _buf) == 0 ) {
> +if (  S_ISDIR(stat_buf.st_mode) )
> +  continue;
> +  }
> +}
> +  }
>  }
>}
>free(bufr);
> --
> 1.9.1
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel