add symlink link target field v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 16 Jan 2019 18:16:07 +0100
branchv_0
changeset 7 8d73bff730a7
parent 6 35607c973cf5
child 8 eb1ecb37c6b7
add symlink link target field
src/CLIParser.h
src/FileAttributeFinder.h
src/FilesystemCommand.h
--- a/src/CLIParser.h	Wed Jan 16 18:01:49 2019 +0100
+++ b/src/CLIParser.h	Wed Jan 16 18:16:07 2019 +0100
@@ -41,7 +41,9 @@
 		// c.fields.push_back(RequestedField(RequestedField::GROUP_FILE, FileAttributeFinder::FIELD_PATH_CANONICAL));
 		// c.fields.push_back(RequestedField(RequestedField::GROUP_FILE, FileAttributeFinder::FIELD_NAME));
 		c.fields.push_back(RequestedField(RequestedField::GROUP_FILE, FileAttributeFinder::FIELD_TYPE));
+		// c.fields.push_back(RequestedField(RequestedField::GROUP_FILE, FileAttributeFinder::FIELD_TYPE,{L"type_a", L"type_b"}));
 		c.fields.push_back(RequestedField(RequestedField::GROUP_FILE, FileAttributeFinder::FIELD_SYMLINK_TARGET_TYPE));
+		// c.fields.push_back(RequestedField(RequestedField::GROUP_FILE, FileAttributeFinder::FIELD_SYMLINK_TARGET));
 		c.fields.push_back(RequestedField(RequestedField::GROUP_FILE, FileAttributeFinder::FIELD_SIZE));
 		c.fields.push_back(RequestedField(RequestedField::GROUP_FILE, FileAttributeFinder::FIELD_OWNER));
 		c.fields.push_back(RequestedField(RequestedField::GROUP_FILE, FileAttributeFinder::FIELD_GROUP));
--- a/src/FileAttributeFinder.h	Wed Jan 16 18:01:49 2019 +0100
+++ b/src/FileAttributeFinder.h	Wed Jan 16 18:16:07 2019 +0100
@@ -78,6 +78,7 @@
 	static const string_t FIELD_PATH_CANONICAL;
 	static const string_t FIELD_TYPE;
 	static const string_t FIELD_SYMLINK_TARGET_TYPE;
+	static const string_t FIELD_SYMLINK_TARGET;
 	static const string_t FIELD_OWNER;
 	static const string_t FIELD_GROUP;
 
@@ -118,6 +119,8 @@
 					writer->writeAttribute(getType(currentFile, true));
 				} else if (field.name == FIELD_SYMLINK_TARGET_TYPE) {
 					writer->writeAttribute(getType(currentFile, false));
+				} else if (field.name == FIELD_SYMLINK_TARGET) {
+					writer->writeAttribute(fs::is_symlink(currentFile) ? fs::read_symlink(currentFile).wstring() : L""); // TODO: null value (when supported)
 				} else if (field.name == FIELD_SIZE) {
 					integer_t size = fs::is_regular_file(currentFile) ? fs::file_size(currentFile) : 0;
 					writer->writeAttribute(&size, typeid (size));
@@ -146,6 +149,7 @@
 const string_t FileAttributeFinder::FIELD_PATH_CANONICAL = L"path_canonical";
 const string_t FileAttributeFinder::FIELD_TYPE = L"type";
 const string_t FileAttributeFinder::FIELD_SYMLINK_TARGET_TYPE = L"symlink_target_type";
+const string_t FileAttributeFinder::FIELD_SYMLINK_TARGET = L"symlink_target";
 const string_t FileAttributeFinder::FIELD_OWNER = L"owner";
 const string_t FileAttributeFinder::FIELD_GROUP = L"group";
 
--- a/src/FilesystemCommand.h	Wed Jan 16 18:01:49 2019 +0100
+++ b/src/FilesystemCommand.h	Wed Jan 16 18:16:07 2019 +0100
@@ -101,13 +101,14 @@
 			for (RequestedField field : configuration.fields) {
 				AttributeFinder* finder = attributeFinders[field.group]; // should not be nullptr, because already checked while writing the relation metadata
 
+				// TODO: links to non-existent files are currently treated as non-existent files → we still can return the type and symlink_target values
 				if (exists || (field.group == RequestedField::GROUP_FILE && field.name == FileAttributeFinder::FIELD_PATH_ORIGINAL)) {
 					finder->writeField(writer.get(), field);
 				} else {
 					finder->writeEmptyField(writer.get(), field);
 				}
 			}
-			
+
 			for (auto& finder : attributeFinders) finder.second->endFile();
 		}
 	}