HostFileSystem -> FileSystemUnderPath

The class is also used by recovery, so moving it to libvintf.
Test: pass

Change-Id: I735212b5ce53a0ba440686ced02feebc51a14841
diff --git a/FileSystem.cpp b/FileSystem.cpp
index e0d09e1..c239488 100644
--- a/FileSystem.cpp
+++ b/FileSystem.cpp
@@ -77,6 +77,27 @@
     return NAME_NOT_FOUND;
 }
 
+FileSystemUnderPath::FileSystemUnderPath(const std::string& rootdir) {
+    mRootDir = rootdir;
+    if (!mRootDir.empty() && mRootDir.back() != '/') {
+        mRootDir.push_back('/');
+    }
+}
+
+status_t FileSystemUnderPath::fetch(const std::string& path, std::string* fetched,
+                                    std::string* error) const {
+    return mImpl.fetch(mRootDir + path, fetched, error);
+}
+
+status_t FileSystemUnderPath::listFiles(const std::string& path, std::vector<std::string>* out,
+                                        std::string* error) const {
+    return mImpl.listFiles(mRootDir + path, out, error);
+}
+
+const std::string& FileSystemUnderPath::getRootDir() const {
+    return mRootDir;
+}
+
 }  // namespace details
 }  // namespace vintf
 }  // namespace android
diff --git a/check_vintf.cpp b/check_vintf.cpp
index e4941bd..b11daf5 100644
--- a/check_vintf.cpp
+++ b/check_vintf.cpp
@@ -43,24 +43,21 @@
 // command line arguments
 using Args = std::multimap<Option, std::string>;
 
-class HostFileSystem : public FileSystem {
+class HostFileSystem : public FileSystemUnderPath {
    public:
-    HostFileSystem(const std::string& rootdir) {
-        mRootDir = rootdir;
-        if (!mRootDir.empty() && mRootDir.back() != '/') {
-            mRootDir.push_back('/');
-        }
-    }
+    HostFileSystem(const std::string& rootdir) : FileSystemUnderPath(rootdir) {}
     status_t fetch(const std::string& path, std::string* fetched,
                    std::string* error) const override {
-        status_t status = mImpl.fetch(mRootDir + path, fetched, error);
-        std::cerr << "Debug: Fetch '" << mRootDir << path << "': " << toString(status) << std::endl;
+        status_t status = FileSystemUnderPath::fetch(path, fetched, error);
+        std::cerr << "Debug: Fetch '" << getRootDir() << path << "': " << toString(status)
+                  << std::endl;
         return status;
     }
     status_t listFiles(const std::string& path, std::vector<std::string>* out,
                        std::string* error) const override {
-        status_t status = mImpl.listFiles(mRootDir + path, out, error);
-        std::cerr << "Debug: List '" << mRootDir << path << "': " << toString(status) << std::endl;
+        status_t status = FileSystemUnderPath::listFiles(path, out, error);
+        std::cerr << "Debug: List '" << getRootDir() << path << "': " << toString(status)
+                  << std::endl;
         return status;
     }
 
@@ -68,8 +65,6 @@
     static std::string toString(status_t status) {
         return status == OK ? "SUCCESS" : strerror(-status);
     }
-    std::string mRootDir;
-    FileSystemImpl mImpl;
 };
 
 class PresetPropertyFetcher : public PropertyFetcher {
diff --git a/include/vintf/FileSystem.h b/include/vintf/FileSystem.h
index b6cc087..6fd375b 100644
--- a/include/vintf/FileSystem.h
+++ b/include/vintf/FileSystem.h
@@ -61,6 +61,23 @@
     status_t listFiles(const std::string&, std::vector<std::string>*, std::string*) const;
 };
 
+// The root is mounted to a given path.
+class FileSystemUnderPath : public FileSystem {
+   public:
+    FileSystemUnderPath(const std::string& rootdir);
+    virtual status_t fetch(const std::string& path, std::string* fetched,
+                           std::string* error) const override;
+    virtual status_t listFiles(const std::string& path, std::vector<std::string>* out,
+                               std::string* error) const override;
+
+   protected:
+    const std::string& getRootDir() const;
+
+   private:
+    std::string mRootDir;
+    FileSystemImpl mImpl;
+};
+
 }  // namespace details
 }  // namespace vintf
 }  // namespace android