23 #include <relpipe/writer/typedefs.h> |
23 #include <relpipe/writer/typedefs.h> |
24 #include <relpipe/writer/AttributeMetadata.h> |
24 #include <relpipe/writer/AttributeMetadata.h> |
25 #include <relpipe/writer/RelationalWriter.h> |
25 #include <relpipe/writer/RelationalWriter.h> |
26 |
26 |
27 #include "RequestedField.h" |
27 #include "RequestedField.h" |
|
28 #include "AttributeFinder.h" |
28 |
29 |
29 namespace relpipe { |
30 namespace relpipe { |
30 namespace in { |
31 namespace in { |
31 namespace filesystem { |
32 namespace filesystem { |
32 |
33 |
35 |
36 |
36 class FileAttributeFinder : public AttributeFinder { |
37 class FileAttributeFinder : public AttributeFinder { |
37 private: |
38 private: |
38 std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings. |
39 std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings. |
39 |
40 |
40 fs::path currentFile; |
|
41 string_t currentOwner; |
41 string_t currentOwner; |
42 string_t currentGroup; |
42 string_t currentGroup; |
43 |
43 |
44 string_t getType(const fs::path& file, bool x) { |
44 string_t getType(const fs::path& file, bool x) { |
45 // TODO: Use whole words? (letters are compatible with find -type) |
45 // TODO: Use whole words? (letters are compatible with find -type) |
93 } else { |
93 } else { |
94 return {}; |
94 return {}; |
95 } |
95 } |
96 } |
96 } |
97 |
97 |
98 void startFile(const fs::path& file) override { |
|
99 currentFile = file; |
|
100 }; |
|
101 |
|
102 void endFile() override { |
98 void endFile() override { |
|
99 AttributeFinder::endFile(); |
103 currentOwner.clear(); |
100 currentOwner.clear(); |
104 currentGroup.clear(); |
101 currentGroup.clear(); |
105 }; |
102 }; |
106 |
103 |
107 virtual void writeField(RelationalWriter* writer, const RequestedField& field) override { |
104 virtual void writeField(RelationalWriter* writer, const RequestedField& field) override { |
108 if (field.group == RequestedField::GROUP_FILE) { |
105 if (field.group == RequestedField::GROUP_FILE) { |
109 for (string_t alias : field.getAliases()) { |
106 for (string_t alias : field.getAliases()) { |
110 if (field.name == FIELD_NAME) { |
107 if (field.name == FIELD_NAME) { |
111 writer->writeAttribute(currentFile.filename().wstring()); |
108 writer->writeAttribute(currentFile.filename().wstring()); |
112 } else if (field.name == FIELD_PATH_ORIGINAL) { |
109 } else if (field.name == FIELD_PATH_ORIGINAL) { |
113 writer->writeAttribute(currentFile.wstring()); |
110 writer->writeAttribute(convertor.from_bytes(currentFileRaw)); |
114 } else if (field.name == FIELD_PATH_ABSOLUTE) { |
111 } else if (field.name == FIELD_PATH_ABSOLUTE) { |
115 writer->writeAttribute(fs::absolute(currentFile).wstring()); |
112 writer->writeAttribute(fs::absolute(currentFile).wstring()); |
116 } else if (field.name == FIELD_PATH_CANONICAL) { |
113 } else if (field.name == FIELD_PATH_CANONICAL) { |
117 writer->writeAttribute(fs::canonical(currentFile).wstring()); |
114 writer->writeAttribute(fs::canonical(currentFile).wstring()); |
118 } else if (field.name == FIELD_TYPE) { |
115 } else if (field.name == FIELD_TYPE) { |