src/FilesystemCommand.h
branchv_0
changeset 52 fea625f0a096
parent 32 bccda5688d71
--- a/src/FilesystemCommand.h	Sun Jan 19 18:41:32 2020 +0100
+++ b/src/FilesystemCommand.h	Mon Jan 20 12:39:22 2020 +0100
@@ -16,28 +16,7 @@
  */
 #pragma once
 
-#include <cstdlib>
-#include <iostream>
-#include <sstream>
-#include <string>
-#include <vector>
-#include <map>
-#include <algorithm>
-#include <filesystem>
-
-#include <pwd.h>
-#include <grp.h>
-#include <sys/stat.h>
-
-#include <sys/xattr.h>
-
-#include <relpipe/writer/typedefs.h>
-
-#include "Configuration.h"
-#include "AttributeFinder.h"
-#include "FileAttributeFinder.h"
-#include "XattrAttributeFinder.h"
-#include "StreamletAttributeFinder.h"
+#include "FilesystemCommandBase.h"
 
 namespace relpipe {
 namespace in {
@@ -46,31 +25,9 @@
 namespace fs = std::filesystem;
 using namespace relpipe::writer;
 
-class FilesystemCommand {
+class FilesystemCommand : public FilesystemCommandBase {
 private:
-	std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
-
-	FileAttributeFinder fileAttributeFinder;
-	StreamletAttributeFinder execAttributeFinder;
-	XattrAttributeFinder xattrAttributeFinder;
-
-	std::map<string_t, AttributeFinder*> attributeFinders{
-		{RequestedField::GROUP_FILE, &fileAttributeFinder},
-		{RequestedField::GROUP_STREAMLET, &execAttributeFinder},
-		{RequestedField::GROUP_XATTR, &xattrAttributeFinder}};
-
-	void reset(std::stringstream& stream) {
-		stream.str("");
-		stream.clear();
-	}
-
-	bool readNext(std::istream& input, std::stringstream& originalName) {
-		for (char ch; input.get(ch);) {
-			if (ch == 0) return true;
-			else originalName << ch;
-		}
-		return originalName.tellp();
-	}
+	std::map<string_t, std::shared_ptr<AttributeFinder>> attributeFinders = createAttributeFinders();
 
 public:
 
@@ -81,7 +38,7 @@
 
 		std::vector<AttributeMetadata> attributesMetadata;
 		for (RequestedField field : configuration.fields) {
-			AttributeFinder* finder = attributeFinders[field.group];
+			std::shared_ptr<AttributeFinder> finder = attributeFinders[field.group];
 			if (finder) for (AttributeMetadata m : finder->toMetadata(writer.get(), relationName, field)) attributesMetadata.push_back(m);
 			else throw RelpipeWriterException(L"Unsupported field group: " + field.group);
 		}
@@ -102,7 +59,7 @@
 			for (auto& finder : attributeFinders) finder.second->startFile(file, originalName.str(), exists);
 
 			for (RequestedField field : configuration.fields) {
-				AttributeFinder* finder = attributeFinders[field.group]; // should not be nullptr, because already checked while writing the relation metadata
+				std::shared_ptr<AttributeFinder> finder = attributeFinders[field.group]; // should not be nullptr, because already checked while writing the relation metadata
 				finder->writeField(writer.get(), relationName, field);
 			}