[haiku-commits] r40213 - haiku/trunk/src/bin/package

  • From: zooey@xxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 12 Jan 2011 15:45:57 +0100 (CET)

Author: zooey
Date: 2011-01-12 15:45:57 +0100 (Wed, 12 Jan 2011)
New Revision: 40213
Changeset: http://dev.haiku-os.org/changeset/40213

Modified:
   haiku/trunk/src/bin/package/command_create.cpp
Log:
* support "." as parameter when creating a package, in order to
  simplify creating a package for the contents of the current folder

Modified: haiku/trunk/src/bin/package/command_create.cpp
===================================================================
--- haiku/trunk/src/bin/package/command_create.cpp      2011-01-12 14:28:58 UTC 
(rev 40212)
+++ haiku/trunk/src/bin/package/command_create.cpp      2011-01-12 14:45:57 UTC 
(rev 40213)
@@ -6,6 +6,7 @@
 
 #include "package.h"
 
+#include <dirent.h>
 #include <errno.h>
 #include <getopt.h>
 #include <stdio.h>
@@ -74,10 +75,30 @@
 
        // add files
        for (int i = 0; i < fileNameCount; i++) {
-               error = packageWriter.AddEntry(fileNames[i]);
+               if (strcmp(fileNames[i], ".") == 0) {
+                       DIR* dir = opendir (".");
+                       if (dir == NULL) {
+                               fprintf(stderr, "Error: Failed to opendir '.': 
%s\n",
+                                       strerror(errno));
+                               return 1;
+                       }
+                       while (dirent* entry = readdir(dir)) {
+                               if (strcmp(entry->d_name, ".") == 0
+                                       || strcmp(entry->d_name, "..") == 0)
+                                       continue;
+                               error = packageWriter.AddEntry(entry->d_name);
+printf("AddEntry(\"%s\"): %s\n", entry->d_name, strerror(error));
+                               if (error != B_OK)
+                                       return 1;
+                       }
+                       closedir (dir);
+
+               } else {
+                       error = packageWriter.AddEntry(fileNames[i]);
 printf("AddEntry(\"%s\"): %s\n", fileNames[i], strerror(error));
-               if (error != B_OK)
-                       return 1;
+                       if (error != B_OK)
+                               return 1;
+               }
        }
 
        // write the package


Other related posts: