]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Improve directory order; make sure a directory entry is exposed
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 31 Oct 2009 03:13:50 +0000 (23:13 -0400)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 31 Oct 2009 03:13:50 +0000 (23:13 -0400)
after its parent especially sub directories under the rr_moved
directory.

SVN-Revision: 1549

libarchive/archive_read_support_format_iso9660.c

index 8be751066e0070a2e5902822d83d0d30db16e62a..cf89f08468f4f03cf6558ccc29c516dc0be55ba4 100644 (file)
@@ -292,6 +292,7 @@ struct file_info {
                struct content  *first;
                struct content  **last;
        } contents;
+       char             exposed;
 };
 
 struct heap_queue {
@@ -400,6 +401,8 @@ static void release_file(struct iso9660 *, struct file_info *);
 static unsigned        toi(const void *p, int n);
 static inline void cache_add_entry(struct iso9660 *iso9660,
                    struct file_info *file);
+static inline void cache_add_to_next_of_parent(struct iso9660 *iso9660,
+                   struct file_info *file);
 static inline struct file_info *cache_get_entry(struct iso9660 *iso9660);
 static void    heap_add_entry(struct iso9660 *iso9660,
                    struct heap_queue *heap, struct file_info *file);
@@ -1072,7 +1075,7 @@ relocate_dir(struct iso9660 *iso9660, struct file_info *file)
                re->parent = file->parent;
                re->parent->refcount++;
                re->parent->subdirs++;
-               cache_add_entry(iso9660, re);
+               cache_add_to_next_of_parent(iso9660, re);
                return (1);
        } else
                /* This case is wrong pattern. */
@@ -1350,6 +1353,7 @@ archive_read_format_iso9660_read_header(struct archive_read *a,
                /* Directory data has been read completely. */
                iso9660->entry_bytes_remaining = 0;
                iso9660->entry_sparse_offset = 0;
+               file->exposed = 1;
        }
 
        release_file(iso9660, file);
@@ -2552,8 +2556,15 @@ next_cache_entry(struct iso9660 *iso9660)
        int count;
 
        file = cache_get_entry(iso9660);
-       if (file != NULL)
+       if (file != NULL) {
+               while (file->parent != NULL && !file->parent->exposed) {
+                       /* If file's parent is not exposed, it's moved
+                        * to next entry of its parent. */
+                       cache_add_to_next_of_parent(iso9660, file);
+                       file = cache_get_entry(iso9660);
+               }
                return (file);
+       }
 
        file = next_entry(iso9660);
        if (file == NULL)
@@ -2632,6 +2643,16 @@ cache_add_entry(struct iso9660 *iso9660, struct file_info *file)
        iso9660->cache_files.last = &(file->next);
 }
 
+static inline void
+cache_add_to_next_of_parent(struct iso9660 *iso9660, struct file_info *file)
+{
+       file->next = file->parent->next;
+       file->parent->next = file;
+       file->refcount++;
+       if (iso9660->cache_files.last == &(file->parent->next))
+               iso9660->cache_files.last = &(file->next);
+}
+
 static inline struct file_info *
 cache_get_entry(struct iso9660 *iso9660)
 {