Installer: WorkerThread::EntryFilter: Use path map

... instead of implicit comparisons.
This commit is contained in:
Ingo Weinhold
2013-06-02 16:30:58 +02:00
parent ba6f7c8c42
commit f4953ba541
+15 -41
View File
@@ -9,6 +9,9 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <set>
#include <string>
#include <Alert.h> #include <Alert.h>
#include <Autolock.h> #include <Autolock.h>
#include <Catalog.h> #include <Catalog.h>
@@ -84,52 +87,25 @@ class WorkerThread::EntryFilter : public CopyEngine::EntryFilter {
public: public:
EntryFilter(const char* sourceDirectory) EntryFilter(const char* sourceDirectory)
{ {
// init BEntry pointing to /var try {
// There is no other way to retrieve the path to the var folder fIgnorePaths.insert(kPackagesDirectoryPath);
// on the source volume. Using find_directory() with fIgnorePaths.insert(kSourcesDirectoryPath);
// B_COMMON_VAR_DIRECTORY will only ever get the var folder on the fIgnorePaths.insert("rr_moved");
// current /boot volume regardless of the volume of "source", which fIgnorePaths.insert("boot.catalog");
// makes sense, since passing a volume is meant to folders that are fIgnorePaths.insert("haiku-boot-floppy.image");
// volume specific, like "trash". fIgnorePaths.insert(kSwapFilePath);
BPath path(sourceDirectory); } catch (std::bad_alloc&) {
if (path.Append(kSwapFilePath) == B_OK) }
fSwapFileEntry.SetTo(path.Path());
else
fSwapFileEntry.Unset();
} }
virtual bool ShouldCopyEntry(const BEntry& entry, const char* path, virtual bool ShouldCopyEntry(const BEntry& entry, const char* path,
const struct stat& statInfo, int32 level) const const struct stat& statInfo, int32 level) const
{ {
if (level == 1 && S_ISDIR(statInfo.st_mode)) { if (fIgnorePaths.find(path) != fIgnorePaths.end()) {
if (strcmp(kPackagesDirectoryPath, path) == 0) {
printf("ignoring '%s'.\n", path); printf("ignoring '%s'.\n", path);
return false; return false;
} }
if (strcmp(kSourcesDirectoryPath, path) == 0) {
printf("ignoring '%s'.\n", path);
return false;
}
if (strcmp("rr_moved", path) == 0) {
printf("ignoring '%s'.\n", path);
return false;
}
}
if (level == 1 && S_ISREG(statInfo.st_mode)) {
if (strcmp("boot.catalog", path) == 0) {
printf("ignoring '%s'.\n", path);
return false;
}
if (strcmp("haiku-boot-floppy.image", path) == 0) {
printf("ignoring '%s'.\n", path);
return false;
}
}
if (fSwapFileEntry == entry) {
// current location of var
printf("ignoring swap file\n");
return false;
}
return true; return true;
} }
@@ -146,9 +122,7 @@ public:
} }
private: private:
// TODO: Should be made into a list of BEntris to be ignored, perhaps. std::set<std::string> fIgnorePaths;
// settable by method...
BEntry fSwapFileEntry;
}; };