[haiku-commits] r40816 - haiku/trunk/src/apps/installer

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 5 Mar 2011 17:14:53 +0100 (CET)

Author: stippi
Date: 2011-03-05 17:14:52 +0100 (Sat, 05 Mar 2011)
New Revision: 40816
Changeset: http://dev.haiku-os.org/changeset/40816

Modified:
   haiku/trunk/src/apps/installer/WorkerThread.cpp
   haiku/trunk/src/apps/installer/WorkerThread.h
Log:
 * Mirror all the indices from the source volume to the target volume.
   Note that it would have been an option to invoke mkindex, which has
   a similar mirroring option, in the InstallerInitScript, but I favor
   making Installer depend on as few external tools as possible.
 * Very small cleanup in _PerformInstall(). It should be broken up more
   into individual methods.


Modified: haiku/trunk/src/apps/installer/WorkerThread.cpp
===================================================================
--- haiku/trunk/src/apps/installer/WorkerThread.cpp     2011-03-05 15:52:49 UTC 
(rev 40815)
+++ haiku/trunk/src/apps/installer/WorkerThread.cpp     2011-03-05 16:14:52 UTC 
(rev 40816)
@@ -6,6 +6,7 @@
 
 #include "WorkerThread.h"
 
+#include <errno.h>
 #include <stdio.h>
 
 #include <Alert.h>
@@ -15,6 +16,7 @@
 #include <DiskDeviceVisitor.h>
 #include <DiskDeviceTypes.h>
 #include <FindDirectory.h>
+#include <fs_index.h>
 #include <Locale.h>
 #include <Menu.h>
 #include <MenuItem.h>
@@ -249,7 +251,10 @@
 {
        CALLED();
 
-       BPath targetDirectory, srcDirectory, trashPath, testPath;
+       BPath targetDirectory;
+       BPath srcDirectory;
+       BPath trashPath;
+       BPath testPath;
        BDirectory targetDir;
        BDiskDevice device;
        BPartition* partition;
@@ -390,13 +395,19 @@
 
        _LaunchInitScript(targetDirectory);
 
-       // let the engine collect information for the progress bar later on
+       // Mirror all the indices which are present on the source volume onto
+       // the target volume
+       err = _MirrorIndices(srcDirectory, targetDirectory);
+       if (err != B_OK)
+               goto error;
+
+       // Let the engine collect information for the progress bar later on
        engine.ResetTargets(srcDirectory.Path());
        err = engine.CollectTargets(srcDirectory.Path(), fCancelSemaphore);
        if (err != B_OK)
                goto error;
 
-       // collect selected packages also
+       // Collect selected packages also
        if (fPackages) {
                BPath pkgRootDir(srcDirectory.Path(), PACKAGES_DIRECTORY);
                int32 count = fPackages->CountItems();
@@ -466,6 +477,65 @@
 
 
 status_t
+WorkerThread::_MirrorIndices(const BPath& sourceDirectory,
+       const BPath& targetDirectory) const
+{
+       dev_t sourceDevice = dev_for_path(sourceDirectory.Path());
+       if (sourceDevice < 0)
+               return (status_t)sourceDevice;
+       dev_t targetDevice = dev_for_path(sourceDirectory.Path());
+       if (targetDevice < 0)
+               return (status_t)targetDevice;
+       DIR* indices = fs_open_index_dir(sourceDevice);
+       if (indices == NULL) {
+               if (errno == B_ENTRY_NOT_FOUND || errno == B_OK) {
+                       // Assume source volume has no indices. TODO: That is 
likely not a
+                       // valid situation, perhaps return an error instead?
+                       return B_OK;
+               }
+               printf("%s: fs_open_index_dir(): (%d) %s\n", 
sourceDirectory.Path(),
+                       errno, strerror(errno));
+               return errno;
+       }
+       while (true) {
+               dirent* index = fs_read_index_dir(indices);
+               if (index == NULL) {
+                       if (errno != B_ENTRY_NOT_FOUND && errno != B_OK) {
+                               printf("%s: fs_read_index_dir: (%d) %s\n",
+                                       sourceDirectory.Path(), errno, 
strerror(errno));
+                               return errno;
+                       }
+                       break;
+               }
+               if (!strcmp(index->d_name, "name")
+                       || !strcmp(index->d_name, "size")
+                       || !strcmp(index->d_name, "last_modified")) {
+                       continue;
+               }
+
+               index_info info;
+               if (fs_stat_index(sourceDevice, index->d_name, &info) != B_OK) {
+                       printf("Failed to mirror index %s: fs_stat_index(): 
(%d) %s\n",
+                               index->d_name, errno, strerror(errno));
+                       return errno;
+               }
+
+               uint32 flags = 0;
+                       // Flags are always 0 for the moment.
+               if (fs_create_index(targetDevice, index->d_name, info.type, 
flags)
+                       != B_OK) {
+                       if (errno == B_FILE_EXISTS)
+                               continue;
+                       printf("Failed to mirror index %s: fs_create_index(): 
(%d) %s\n",
+                               index->d_name, errno, strerror(errno));
+                       return errno;
+               }
+       }
+       return B_OK;
+}
+
+
+status_t
 WorkerThread::_ProcessZipPackages(const char* sourcePath,
        const char* targetPath, ProgressReporter* reporter, BList& unzipEngines)
 {

Modified: haiku/trunk/src/apps/installer/WorkerThread.h
===================================================================
--- haiku/trunk/src/apps/installer/WorkerThread.h       2011-03-05 15:52:49 UTC 
(rev 40815)
+++ haiku/trunk/src/apps/installer/WorkerThread.h       2011-03-05 16:14:52 UTC 
(rev 40816)
@@ -44,6 +44,8 @@
 
                        void                            _PerformInstall(BMenu* 
srcMenu,
                                                                        BMenu* 
dstMenu);
+                       status_t                        _MirrorIndices(const 
BPath& srcDirectory,
+                                                                       const 
BPath& targetDirectory) const;
                        status_t                        
_ProcessZipPackages(const char* sourcePath,
                                                                        const 
char* targetPath,
                                                                        
ProgressReporter* reporter,


Other related posts: