[gcab: 2/4] Removed gcab_folder_get_ndatablocks and count the number of blocks written instead




commit 5f4133a7af1f0363156df7ba7aa7abf2487e2a5b
Author: Joel Holdsworth <jholdsworth nvidia com>
Date:   Thu Jul 21 20:40:30 2022 +0100

    Removed gcab_folder_get_ndatablocks and count the number of blocks written instead

 libgcab/gcab-cabinet.c |  4 +++-
 libgcab/gcab-folder.c  | 15 ---------------
 libgcab/gcab-priv.h    |  1 -
 3 files changed, 3 insertions(+), 17 deletions(-)
---
diff --git a/libgcab/gcab-cabinet.c b/libgcab/gcab-cabinet.c
index edf5a98..57c5962 100644
--- a/libgcab/gcab-cabinet.c
+++ b/libgcab/gcab-cabinet.c
@@ -300,7 +300,7 @@ gcab_cabinet_write (GCabCabinet *self,
 
     folder.typecomp = gcab_folder_get_comptype (cabfolder);
     folder.offsetdata = cheader->offsetfiles + nfiles * 16 + sumstr;
-    folder.ndatab = gcab_folder_get_ndatablocks (cabfolder);
+    folder.ndatab = 0;
 
     /* avoid seeking to allow growing output streams */
     for (guint i = 0; i < folder.offsetdata; i++)
@@ -323,6 +323,7 @@ gcab_cabinet_write (GCabCabinet *self,
                                            cancellable, error)) == (DATABLOCKSIZE - offset)) {
             if (!cdata_write (&block, dstream, folder.typecomp, data, DATABLOCKSIZE, &written, cancellable, 
error))
                 return FALSE;
+            folder.ndatab++;
             cheader->size += written;
             offset = 0;
         }
@@ -335,6 +336,7 @@ gcab_cabinet_write (GCabCabinet *self,
     if (offset != 0) {
         if (!cdata_write (&block, dstream, folder.typecomp, data, offset, &written, cancellable, error))
             return FALSE;
+        folder.ndatab++;
         cheader->size += written;
     }
 
diff --git a/libgcab/gcab-folder.c b/libgcab/gcab-folder.c
index 67f2ca9..831c68c 100644
--- a/libgcab/gcab-folder.c
+++ b/libgcab/gcab-folder.c
@@ -158,21 +158,6 @@ gcab_folder_class_init (GCabFolderClass *klass)
 
 }
 
-/* calculate the number of datablocks we will need:
-   cabinet files are written in blocks of 32768 bytes */
-G_GNUC_INTERNAL gsize
-gcab_folder_get_ndatablocks (GCabFolder *self)
-{
-    gsize total_size = 0;
-
-    for (GSList *l = self->files; l != NULL; l = l->next) {
-        GCabFile *file = GCAB_FILE (l->data);
-        total_size += gcab_file_get_usize (file);
-    }
-
-    return total_size / DATABLOCKSIZE + 1 ;
-}
-
 /**
  * gcab_folder_get_comptype:
  * @cabfolder: a #GCabFolder
diff --git a/libgcab/gcab-priv.h b/libgcab/gcab-priv.h
index 6d200e5..c951214 100644
--- a/libgcab/gcab-priv.h
+++ b/libgcab/gcab-priv.h
@@ -51,7 +51,6 @@ GFile           *gcab_file_get_gfile                 (GCabFile *file);
 cfile_t         *gcab_file_get_cfile                 (GCabFile *file);
 void             gcab_file_add_attribute             (GCabFile *file, guint32 attribute);
 
-gsize            gcab_folder_get_ndatablocks         (GCabFolder *folder);
 gboolean         gcab_folder_extract                 (GCabFolder *self,
                                                       GDataInputStream *data,
                                                       GFile *path,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]