# HG changeset patch # User František Kučera # Date 1547659190 -3600 # Node ID eb1ecb37c6b7f62ed22f575efbe1797adaf57f37 # Parent 8d73bff730a7099eaa331173d839e584860f5534 interpret empty string as current directory (e.g. result of: find -printf '%P\0') diff -r 8d73bff730a7 -r eb1ecb37c6b7 src/AttributeFinder.h --- a/src/AttributeFinder.h Wed Jan 16 18:16:07 2019 +0100 +++ b/src/AttributeFinder.h Wed Jan 16 18:19:50 2019 +0100 @@ -34,6 +34,9 @@ using namespace relpipe::writer; class AttributeFinder { +protected: + fs::path currentFile; + string currentFileRaw; public: /** @@ -47,14 +50,21 @@ /** * Writing of the record for current file is starting. * Following writeField() calls are related to this file. - * @param file + * @param file path to the file + * @param fileRaw raw file name as it was on the input */ - virtual void startFile(const fs::path& file) = 0; + virtual void startFile(const fs::path& file, const string& fileRaw) { + currentFile = file; + currentFileRaw = fileRaw; + } /** * Writing of the record for current file is finished. All resources linked to this file should be released. */ - virtual void endFile() = 0; + virtual void endFile() { + currentFile.clear(); + currentFileRaw.clear(); + } /** * Writes field attribute(s). The attribute count must match with count of AttributeMetadata returned in toMetadata(). diff -r 8d73bff730a7 -r eb1ecb37c6b7 src/FileAttributeFinder.h --- a/src/FileAttributeFinder.h Wed Jan 16 18:16:07 2019 +0100 +++ b/src/FileAttributeFinder.h Wed Jan 16 18:19:50 2019 +0100 @@ -25,6 +25,7 @@ #include #include "RequestedField.h" +#include "AttributeFinder.h" namespace relpipe { namespace in { @@ -37,7 +38,6 @@ private: std::wstring_convert> convertor; // TODO: support also other encodings. - fs::path currentFile; string_t currentOwner; string_t currentGroup; @@ -95,11 +95,8 @@ } } - void startFile(const fs::path& file) override { - currentFile = file; - }; - void endFile() override { + AttributeFinder::endFile(); currentOwner.clear(); currentGroup.clear(); }; @@ -110,7 +107,7 @@ if (field.name == FIELD_NAME) { writer->writeAttribute(currentFile.filename().wstring()); } else if (field.name == FIELD_PATH_ORIGINAL) { - writer->writeAttribute(currentFile.wstring()); + writer->writeAttribute(convertor.from_bytes(currentFileRaw)); } else if (field.name == FIELD_PATH_ABSOLUTE) { writer->writeAttribute(fs::absolute(currentFile).wstring()); } else if (field.name == FIELD_PATH_CANONICAL) { diff -r 8d73bff730a7 -r eb1ecb37c6b7 src/FilesystemCommand.h --- a/src/FilesystemCommand.h Wed Jan 16 18:16:07 2019 +0100 +++ b/src/FilesystemCommand.h Wed Jan 16 18:19:50 2019 +0100 @@ -86,8 +86,7 @@ for (std::stringstream originalName; readNext(input, originalName); reset(originalName)) { - - fs::path file(originalName.str()); + fs::path file(originalName.str().empty() ? "." : originalName.str()); // interpret empty string as current directory (e.g. result of: find -printf '%P\0') bool exists = false; try { @@ -96,7 +95,7 @@ // we probably do not have permissions to given directory → pretend that the file does not exist } - for (auto& finder : attributeFinders) finder.second->startFile(file); + for (auto& finder : attributeFinders) finder.second->startFile(file, originalName.str()); for (RequestedField field : configuration.fields) { AttributeFinder* finder = attributeFinders[field.group]; // should not be nullptr, because already checked while writing the relation metadata diff -r 8d73bff730a7 -r eb1ecb37c6b7 src/XattrAttributeFinder.h --- a/src/XattrAttributeFinder.h Wed Jan 16 18:16:07 2019 +0100 +++ b/src/XattrAttributeFinder.h Wed Jan 16 18:19:50 2019 +0100 @@ -37,8 +37,6 @@ private: std::wstring_convert> convertor; // TODO: support also other encodings. - fs::path currentFile; - string_t getXattr(const fs::path& file, const string_t& attributeName) { // TODO: review, test on multiple platforms // TODO: improve documentation in xattr.h in glibc @@ -65,13 +63,6 @@ } } - void startFile(const fs::path& file) override { - currentFile = file; - }; - - void endFile() override { - }; - virtual void writeField(RelationalWriter* writer, const RequestedField& field) override { for (string_t alias : field.getAliases()) { if (field.group == RequestedField::GROUP_XATTR) writer->writeAttribute(getXattr(currentFile, field.name));