distinguish link type and link target type v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 16 Jan 2019 18:01:49 +0100
branchv_0
changeset 6 35607c973cf5
parent 5 ec661baf433a
child 7 8d73bff730a7
distinguish link type and link target type
src/CLIParser.h
src/FileAttributeFinder.h
--- a/src/CLIParser.h	Wed Jan 16 17:48:06 2019 +0100
+++ b/src/CLIParser.h	Wed Jan 16 18:01:49 2019 +0100
@@ -41,6 +41,7 @@
 		// 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_SYMLINK_TARGET_TYPE));
 		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 17:48:06 2019 +0100
+++ b/src/FileAttributeFinder.h	Wed Jan 16 18:01:49 2019 +0100
@@ -41,10 +41,10 @@
 	string_t currentOwner;
 	string_t currentGroup;
 
-	string_t getType(const fs::path& file) {
+	string_t getType(const fs::path& file, bool x) {
 		// TODO: Use whole words? (letters are compatible with find -type)
-		if (fs::is_regular_file(file)) return L"f";
-		else if (fs::is_symlink(file)) return L"l"; // symlinks to directories are both symlinks and directories
+		if (fs::is_symlink(file) && x) return L"l"; // symlinks are both symlinks and files/directories/etc.
+		else if (fs::is_regular_file(file)) return L"f";
 		else if (fs::is_directory(file)) return L"d";
 		else if (fs::is_fifo(file)) return L"p";
 		else if (fs::is_socket(file)) return L"s";
@@ -77,6 +77,7 @@
 	static const string_t FIELD_PATH_ABSOLUTE;
 	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_OWNER;
 	static const string_t FIELD_GROUP;
 
@@ -114,7 +115,9 @@
 				} else if (field.name == FIELD_PATH_CANONICAL) {
 					writer->writeAttribute(fs::canonical(currentFile).wstring());
 				} else if (field.name == FIELD_TYPE) {
-					writer->writeAttribute(getType(currentFile));
+					writer->writeAttribute(getType(currentFile, true));
+				} else if (field.name == FIELD_SYMLINK_TARGET_TYPE) {
+					writer->writeAttribute(getType(currentFile, false));
 				} else if (field.name == FIELD_SIZE) {
 					integer_t size = fs::is_regular_file(currentFile) ? fs::file_size(currentFile) : 0;
 					writer->writeAttribute(&size, typeid (size));
@@ -142,6 +145,7 @@
 const string_t FileAttributeFinder::FIELD_PATH_ABSOLUTE = L"path_absolute";
 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_OWNER = L"owner";
 const string_t FileAttributeFinder::FIELD_GROUP = L"group";