73 |
73 |
74 string_t fetchRelationName(Configuration* configuration) { |
74 string_t fetchRelationName(Configuration* configuration) { |
75 return configuration->relation.empty() ? L"filesystem" : configuration->relation; |
75 return configuration->relation.empty() ? L"filesystem" : configuration->relation; |
76 } |
76 } |
77 |
77 |
78 void writeHeader(RelationalWriter* writer, std::map<string_t, std::shared_ptr < AttributeFinder>> attributeFinders, string_t relationName, std::vector<RequestedField>* fields) { |
78 void writeHeader(RelationalWriter* writer, std::map<string_t, std::shared_ptr < AttributeFinder>> attributeFinders, string_t relationName, std::vector<RequestedField>* fields, bool writeHeader = true) { |
79 std::vector<AttributeMetadata> attributesMetadata; |
79 std::vector<AttributeMetadata> attributesMetadata; |
80 for (RequestedField field : *fields) { |
80 for (RequestedField field : *fields) { |
81 std::shared_ptr<AttributeFinder> finder = attributeFinders[field.group]; |
81 std::shared_ptr<AttributeFinder> finder = attributeFinders[field.group]; |
82 if (finder) for (AttributeMetadata m : finder->toMetadata(writer, relationName, field)) attributesMetadata.push_back(m); |
82 if (finder) for (AttributeMetadata m : finder->toMetadata(writer, relationName, field)) attributesMetadata.push_back(m); |
83 else throw RelpipeWriterException(L"Unsupported field group: " + field.group); |
83 else throw RelpipeWriterException(L"Unsupported field group: " + field.group); |
84 } |
84 } |
85 |
85 |
86 writer->startRelation(relationName, attributesMetadata, true); |
86 writer->startRelation(relationName, attributesMetadata, writeHeader); |
|
87 } |
|
88 |
|
89 void processSingleFile(std::shared_ptr<RelationalWriter> writer, std::stringstream& originalName, std::map<string_t, std::shared_ptr < AttributeFinder>>&attributeFinders, Configuration& configuration, string_t relationName) { |
|
90 fs::path file(originalName.str().empty() ? "." : originalName.str()); // interpret empty string as current directory (e.g. result of: find -printf '%P\0') |
|
91 bool exists = false; |
|
92 |
|
93 try { |
|
94 exists = fs::exists(file); |
|
95 } catch (const fs::filesystem_error& e) { |
|
96 // we probably do not have permissions to given directory → pretend that the file does not exist |
|
97 } |
|
98 |
|
99 for (auto& finder : attributeFinders) finder.second->startFile(file, originalName.str(), exists); |
|
100 |
|
101 for (RequestedField field : configuration.fields) { |
|
102 std::shared_ptr<AttributeFinder> finder = attributeFinders[field.group]; // should not be nullptr, because already checked while writing the relation metadata |
|
103 finder->writeField(writer.get(), relationName, field); |
|
104 } |
|
105 |
|
106 for (auto& finder : attributeFinders) finder.second->endFile(); |
87 } |
107 } |
88 |
108 |
89 public: |
109 public: |
90 |
110 |
91 virtual ~FilesystemCommand() = default; |
111 virtual ~FilesystemCommand() = default; |