COMMON: Various path related fixes in archives

This commit is contained in:
Le Philousophe 2023-09-02 16:25:53 +02:00 committed by Eugene Sandulenko
parent 28b63470f0
commit 56552fa282
2 changed files with 29 additions and 14 deletions

@ -122,7 +122,7 @@ SeekableReadStream *Archive::createReadStreamForMemberAltStream(const Path &path
return nullptr; return nullptr;
} }
Common::Error Archive::dumpArchive(String destPath) { Common::Error Archive::dumpArchive(const Path &destPath) {
Common::ArchiveMemberList files; Common::ArchiveMemberList files;
listMembers(files); listMembers(files);
@ -135,7 +135,7 @@ Common::Error Archive::dumpArchive(String destPath) {
debug(1, "File: %s", filePath.toString().c_str()); debug(1, "File: %s", filePath.toString().c_str());
// skip if f represents a directory // skip if f represents a directory
if (filePath.toString().lastChar() == '/') continue; if (filePath.isSeparatorTerminated()) continue;
Common::SeekableReadStream *stream = f->createReadStream(); Common::SeekableReadStream *stream = f->createReadStream();
@ -149,9 +149,9 @@ Common::Error Archive::dumpArchive(String destPath) {
stream->read(data, len); stream->read(data, len);
Common::DumpFile out; Common::DumpFile out;
Common::Path outPath = Common::Path(destPath).join(filePath); Common::Path outPath = destPath.join(filePath);
if (!out.open(outPath.toString(), true)) { if (!out.open(outPath, true)) {
return Common::Error(Common::kCreatingFileFailed, "Cannot open/create dump file " + outPath.toString()); return Common::Error(Common::kCreatingFileFailed, "Cannot open/create dump file " + outPath.toString(Common::Path::kNativeSeparator));
} else { } else {
uint32 writtenBytes = out.write(data, len); uint32 writtenBytes = out.write(data, len);
if (writtenBytes < len) { if (writtenBytes < len) {
@ -298,7 +298,7 @@ void SearchSet::add(const String &name, Archive *archive, int priority, bool aut
} }
void SearchSet::addDirectory(const String &name, const String &directory, int priority, int depth, bool flat) { void SearchSet::addDirectory(const String &name, const Path &directory, int priority, int depth, bool flat) {
FSNode dir(directory); FSNode dir(directory);
addDirectory(name, dir, priority, depth, flat); addDirectory(name, dir, priority, depth, flat);
} }
@ -310,6 +310,13 @@ void SearchSet::addDirectory(const String &name, const FSNode &dir, int priority
add(name, new FSDirectory(dir, depth, flat, _ignoreClashes), priority); add(name, new FSDirectory(dir, depth, flat, _ignoreClashes), priority);
} }
void SearchSet::addDirectory(const Path &directory, int priority, int depth, bool flat) {
addDirectory(directory.toString(), directory, priority, depth, flat);
}
void SearchSet::addDirectory(const FSNode &directory, int priority, int depth, bool flat) {
addDirectory(directory.getPath().toString(), directory, priority, depth, flat);
}
void SearchSet::addSubDirectoriesMatching(const FSNode &directory, String origPattern, bool ignoreCase, int priority, int depth, bool flat) { void SearchSet::addSubDirectoriesMatching(const FSNode &directory, String origPattern, bool ignoreCase, int priority, int depth, bool flat) {
FSList subDirs; FSList subDirs;
if (!directory.getChildren(subDirs)) if (!directory.getChildren(subDirs))
@ -344,11 +351,13 @@ void SearchSet::addSubDirectoriesMatching(const FSNode &directory, String origPa
multipleMatches[name] = true; multipleMatches[name] = true;
} else { } else {
if (matchIter->_value) { if (matchIter->_value) {
warning("Clash in case for match of pattern \"%s\" found in directory \"%s\": \"%s\"", pattern.c_str(), directory.getPath().c_str(), matchIter->_key.c_str()); warning("Clash in case for match of pattern \"%s\" found in directory \"%s\": \"%s\"", pattern.c_str(),
directory.getPath().toString(Common::Path::kNativeSeparator).c_str(), matchIter->_key.c_str());
matchIter->_value = false; matchIter->_value = false;
} }
warning("Clash in case for match of pattern \"%s\" found in directory \"%s\": \"%s\"", pattern.c_str(), directory.getPath().c_str(), name.c_str()); warning("Clash in case for match of pattern \"%s\" found in directory \"%s\": \"%s\"", pattern.c_str(),
directory.getPath().toString(Common::Path::kNativeSeparator).c_str(), name.c_str());
} }
if (nextPattern.empty()) if (nextPattern.empty())

@ -22,14 +22,14 @@
#ifndef COMMON_ARCHIVE_H #ifndef COMMON_ARCHIVE_H
#define COMMON_ARCHIVE_H #define COMMON_ARCHIVE_H
#include "common/str.h" #include "common/error.h"
#include "common/hashmap.h"
#include "common/hash-str.h"
#include "common/list.h" #include "common/list.h"
#include "common/path.h" #include "common/path.h"
#include "common/ptr.h" #include "common/ptr.h"
#include "common/hashmap.h"
#include "common/hash-str.h"
#include "common/singleton.h" #include "common/singleton.h"
#include "common/error.h" #include "common/str.h"
namespace Common { namespace Common {
@ -205,7 +205,7 @@ public:
/** /**
* Dump all files from the archive to the given directory * Dump all files from the archive to the given directory
*/ */
Common::Error dumpArchive(String destPath); Common::Error dumpArchive(const Path &destPath);
/** /**
* Returns the separator used by internal paths in the archive * Returns the separator used by internal paths in the archive
@ -343,13 +343,19 @@ public:
/** /**
* Create and add an FSDirectory by name. * Create and add an FSDirectory by name.
*/ */
void addDirectory(const String &name, const String &directory, int priority = 0, int depth = 1, bool flat = false); void addDirectory(const String &name, const Path &directory, int priority = 0, int depth = 1, bool flat = false);
/** /**
* Create and add an FSDirectory by FSNode. * Create and add an FSDirectory by FSNode.
*/ */
void addDirectory(const String &name, const FSNode &directory, int priority = 0, int depth = 1, bool flat = false); void addDirectory(const String &name, const FSNode &directory, int priority = 0, int depth = 1, bool flat = false);
/**
* Overloads which use directory path as name
*/
void addDirectory(const Path &directory, int priority = 0, int depth = 1, bool flat = false);
void addDirectory(const FSNode &directory, int priority = 0, int depth = 1, bool flat = false);
/** /**
* Create and add a subdirectory by name (caseless). * Create and add a subdirectory by name (caseless).
* *