src/PlainFilesystemCommand.h
branchv_0
changeset 59 7471529c0d11
parent 58 4679f67a8324
equal deleted inserted replaced
58:4679f67a8324 59:7471529c0d11
    39 		std::shared_ptr<RelationalWriter> writer(Factory::create(output));
    39 		std::shared_ptr<RelationalWriter> writer(Factory::create(output));
    40 		std::map<string_t, std::shared_ptr < AttributeFinder>> attributeFinders = createAttributeFinders();
    40 		std::map<string_t, std::shared_ptr < AttributeFinder>> attributeFinders = createAttributeFinders();
    41 
    41 
    42 		string_t relationName = fetchRelationName(&configuration);
    42 		string_t relationName = fetchRelationName(&configuration);
    43 		writeHeader(writer.get(), attributeFinders, relationName, &configuration.fields);
    43 		writeHeader(writer.get(), attributeFinders, relationName, &configuration.fields);
    44 		
    44 
    45 
    45 
    46 		for (std::stringstream originalName; readNext(input, originalName); reset(originalName)) {
    46 		for (std::stringstream originalName; readNext(input, originalName); reset(originalName)) {
    47 			fs::path file(originalName.str().empty() ? "." : originalName.str()); // interpret empty string as current directory (e.g. result of: find -printf '%P\0')
    47 			processSingleFile(writer, originalName, attributeFinders, configuration, relationName);
    48 			bool exists = false;
       
    49 
       
    50 			try {
       
    51 				exists = fs::exists(file);
       
    52 			} catch (const fs::filesystem_error& e) {
       
    53 				// we probably do not have permissions to given directory → pretend that the file does not exist
       
    54 			}
       
    55 
       
    56 			for (auto& finder : attributeFinders) finder.second->startFile(file, originalName.str(), exists);
       
    57 
       
    58 			for (RequestedField field : configuration.fields) {
       
    59 				std::shared_ptr<AttributeFinder> finder = attributeFinders[field.group]; // should not be nullptr, because already checked while writing the relation metadata
       
    60 				finder->writeField(writer.get(), relationName, field);
       
    61 			}
       
    62 
       
    63 			for (auto& finder : attributeFinders) finder.second->endFile();
       
    64 		}
    48 		}
    65 	}
    49 	}
    66 };
    50 };
    67 
    51 
    68 }
    52 }