Import upstream version 1.28
[debian/tar] / src / unlink.c
index 6677148ea5ecd976d4a9aa3bbecac42747cf1951..7f86cc5844a16f3aeecd1f96a69a34a2cf80de5d 100644 (file)
@@ -1,6 +1,6 @@
 /* Unlink files.
 
-   Copyright 2009, 2013 Free Software Foundation, Inc.
+   Copyright 2009, 2013-2014 Free Software Foundation, Inc.
 
    This file is part of GNU tar.
 
@@ -73,7 +73,7 @@ flush_deferred_unlinks (bool force)
 {
   struct deferred_unlink *p, *prev = NULL;
   int saved_chdir = chdir_current;
-  
+
   for (p = dunlink_head; p; )
     {
       struct deferred_unlink *next = p->next;
@@ -86,15 +86,16 @@ flush_deferred_unlinks (bool force)
            {
              const char *fname;
 
-             if (p->file_name[0] == 0 ||
-                 strcmp (p->file_name, ".") == 0)
+             if (p->dir_idx
+                 && (p->file_name[0] == 0
+                     || strcmp (p->file_name, ".") == 0))
                {
                  fname = tar_dirname ();
                  chdir_do (p->dir_idx - 1);
                }
              else
                fname = p->file_name;
-                 
+
              if (unlinkat (chdir_fd, fname, AT_REMOVEDIR) != 0)
                {
                  switch (errno)