[tonic] Remove unused portions of filesystem and ensure Windows builds work.

TEST=Test that the target compiles on Windows.

Change-Id: I7f7285840149c1f1c1a3e89b9bf36515cee80572
diff --git a/common/BUILD.gn b/common/BUILD.gn
index f7960bb..4dab864 100644
--- a/common/BUILD.gn
+++ b/common/BUILD.gn
@@ -5,9 +5,10 @@
 source_set("common") {
   visibility = [ "../*" ]
 
-  configs += [ "../:config" ]
+  public_configs = [ "../:config" ]
 
   sources = [
+    "build_config.h",
     "macros.h",
   ]
 }
diff --git a/common/build_config.h b/common/build_config.h
index 74003e8..92d0668 100644
--- a/common/build_config.h
+++ b/common/build_config.h
@@ -47,7 +47,7 @@
 #elif defined(__QNXNTO__)
 #define OS_QNX 1
 #else
-#error Please add support for your platform in lib/fxl/build_config.h
+#error Please add support for your platform in tonic/common/build_config.h
 #endif
 
 // For access to standard BSD features, use OS_BSD instead of a
diff --git a/common/files.h b/common/files.h
deleted file mode 100644
index e69de29..0000000
--- a/common/files.h
+++ /dev/null
diff --git a/file_loader/file_loader.cc b/file_loader/file_loader.cc
index 9667c79..04e5d9f 100644
--- a/file_loader/file_loader.cc
+++ b/file_loader/file_loader.cc
@@ -8,11 +8,9 @@
 #include <memory>
 #include <utility>
 
-#include "filesystem/directory.h"
 #include "filesystem/file.h"
 #include "filesystem/path.h"
 #include "filesystem/portable_unistd.h"
-#include "filesystem/symlink.h"
 #include "tonic/common/macros.h"
 #include "tonic/converter/dart_converter.h"
 #include "tonic/parsers/packages_map.h"
diff --git a/file_loader/file_loader_fuchsia.cc b/file_loader/file_loader_fuchsia.cc
index ced1b0b..f117865 100644
--- a/file_loader/file_loader_fuchsia.cc
+++ b/file_loader/file_loader_fuchsia.cc
@@ -15,7 +15,6 @@
 
 #include "filesystem/directory.h"
 #include "filesystem/file.h"
-#include "filesystem/file_descriptor.h"
 #include "filesystem/path.h"
 #include "filesystem/symlink.h"
 #include "tonic/common/macros.h"
diff --git a/file_loader/file_loader_posix.cc b/file_loader/file_loader_posix.cc
index 086edd5..022b117 100644
--- a/file_loader/file_loader_posix.cc
+++ b/file_loader/file_loader_posix.cc
@@ -8,10 +8,8 @@
 #include <memory>
 #include <utility>
 
-#include "filesystem/directory.h"
 #include "filesystem/file.h"
 #include "filesystem/path.h"
-#include "filesystem/symlink.h"
 #include "tonic/common/macros.h"
 #include "tonic/converter/dart_converter.h"
 #include "tonic/parsers/packages_map.h"
diff --git a/file_loader/file_loader_win.cc b/file_loader/file_loader_win.cc
index f8187e3..7447dc3 100644
--- a/file_loader/file_loader_win.cc
+++ b/file_loader/file_loader_win.cc
@@ -8,7 +8,6 @@
 #include <memory>
 #include <utility>
 
-#include "filesystem/directory.h"
 #include "filesystem/file.h"
 #include "filesystem/path.h"
 #include "tonic/common/macros.h"
@@ -47,13 +46,13 @@
 bool FileLoader::ReadFileToString(const std::string& path,
                                   std::string* result) {
   TONIC_DCHECK(dirfd_ == -1);
-  return files::ReadFileToString(path, result);
+  return filesystem::ReadFileToString(path, result);
 }
 
 std::pair<uint8_t*, intptr_t> FileLoader::ReadFileToBytes(
     const std::string& path) {
   TONIC_DCHECK(dirfd_ == -1);
-  return files::ReadFileToBytes(path);
+  return filesystem::ReadFileToBytes(path);
 }
 
 }  // namespace tonic
diff --git a/filesystem/filesystem/BUILD.gn b/filesystem/filesystem/BUILD.gn
index acd48c9..1fd704f 100644
--- a/filesystem/filesystem/BUILD.gn
+++ b/filesystem/filesystem/BUILD.gn
@@ -13,33 +13,25 @@
 source_set("filesystem") {
   visibility = [ "../*" ]
 
+  configs += [ "../../:config" ]
+
   sources = [
-    "build_config.h",
-    "directory.cc",
-    "directory.h",
     "eintr_wrapper.h",
     "file.cc",
     "file.h",
-    "file_descriptor.cc",
-    "file_descriptor.h",
     "path.h",
     "portable_unistd.h",
-    "scoped_temp_dir.cc",
-    "scoped_temp_dir.h",
-    "symlink.h",
   ]
 
   if (is_win) {
-    sources += [
-      "path_win.cc",
-      "symlink_win.cc",
-    ]
+    sources += [ "path_win.cc" ]
   } else {
-    sources += [
-      "path_posix.cc",
-      "symlink_posix.cc",
-    ]
+    sources += [ "path_posix.cc" ]
   }
 
+  deps = [
+    "../../common",
+  ]
+
   public_configs = [ ":filesystem_config" ]
 }
diff --git a/filesystem/filesystem/build_config.h b/filesystem/filesystem/build_config.h
deleted file mode 100644
index 1da1966..0000000
--- a/filesystem/filesystem/build_config.h
+++ /dev/null
@@ -1,110 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// This file adds defines about the platform we're currently building on.
-//  Operating System:
-//    OS_WIN / OS_MACOSX / OS_LINUX / OS_POSIX (MACOSX or LINUX) /
-//    OS_NACL (NACL_SFI or NACL_NONSFI) / OS_NACL_SFI / OS_NACL_NONSFI
-//  Compiler:
-//    COMPILER_MSVC / COMPILER_GCC
-//  Processor:
-//    ARCH_CPU_X86 / ARCH_CPU_X86_64 / ARCH_CPU_X86_FAMILY (X86 or X86_64)
-//    ARCH_CPU_32_BITS / ARCH_CPU_64_BITS
-
-#ifndef FILESYSTEM_BUILD_CONFIG_H_
-#define FILESYSTEM_BUILD_CONFIG_H_
-
-#if defined(__Fuchsia__)
-#define OS_FUCHSIA 1
-#elif defined(ANDROID)
-#define OS_ANDROID 1
-#elif defined(__APPLE__)
-// only include TargetConditions after testing ANDROID as some android builds
-// on mac don't have this header available and it's not needed unless the target
-// is really mac/ios.
-#include <TargetConditionals.h>
-#define OS_MACOSX 1
-#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
-#define OS_IOS 1
-#endif  // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
-#elif defined(__linux__)
-#define OS_LINUX 1
-// include a system header to pull in features.h for glibc/uclibc macros.
-#include <unistd.h>
-#if defined(__GLIBC__) && !defined(__UCLIBC__)
-// we really are using glibc, not uClibc pretending to be glibc
-#define LIBC_GLIBC 1
-#endif
-#elif defined(_WIN32)
-#define OS_WIN 1
-#elif defined(__FreeBSD__)
-#define OS_FREEBSD 1
-#elif defined(__OpenBSD__)
-#define OS_OPENBSD 1
-#elif defined(__sun)
-#define OS_SOLARIS 1
-#elif defined(__QNXNTO__)
-#define OS_QNX 1
-#else
-#error Please add support for your platform in lib/fxl/build_config.h
-#endif
-
-// For access to standard BSD features, use OS_BSD instead of a
-// more specific macro.
-#if defined(OS_FREEBSD) || defined(OS_OPENBSD)
-#define OS_BSD 1
-#endif
-
-// For access to standard POSIXish features, use OS_POSIX instead of a
-// more specific macro.
-#if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_FREEBSD) ||    \
-    defined(OS_OPENBSD) || defined(OS_SOLARIS) || defined(OS_ANDROID) || \
-    defined(OS_NACL) || defined(OS_QNX)
-#define OS_POSIX 1
-#endif
-
-// Processor architecture detection.  For more info on what's defined, see:
-//   http://msdn.microsoft.com/en-us/library/b0084kay.aspx
-//   http://www.agner.org/optimize/calling_conventions.pdf
-//   or with gcc, run: "echo | gcc -E -dM -"
-#if defined(_M_X64) || defined(__x86_64__)
-#define ARCH_CPU_X86_FAMILY 1
-#define ARCH_CPU_X86_64 1
-#define ARCH_CPU_64_BITS 1
-#define ARCH_CPU_LITTLE_ENDIAN 1
-#elif defined(_M_IX86) || defined(__i386__)
-#define ARCH_CPU_X86_FAMILY 1
-#define ARCH_CPU_X86 1
-#define ARCH_CPU_32_BITS 1
-#define ARCH_CPU_LITTLE_ENDIAN 1
-#elif defined(__ARMEL__)
-#define ARCH_CPU_ARM_FAMILY 1
-#define ARCH_CPU_ARMEL 1
-#define ARCH_CPU_32_BITS 1
-#define ARCH_CPU_LITTLE_ENDIAN 1
-#elif defined(__aarch64__)
-#define ARCH_CPU_ARM_FAMILY 1
-#define ARCH_CPU_ARM64 1
-#define ARCH_CPU_64_BITS 1
-#define ARCH_CPU_LITTLE_ENDIAN 1
-#elif defined(__pnacl__)
-#define ARCH_CPU_32_BITS 1
-#define ARCH_CPU_LITTLE_ENDIAN 1
-#elif defined(__MIPSEL__)
-#if defined(__LP64__)
-#define ARCH_CPU_MIPS64_FAMILY 1
-#define ARCH_CPU_MIPS64EL 1
-#define ARCH_CPU_64_BITS 1
-#define ARCH_CPU_LITTLE_ENDIAN 1
-#else
-#define ARCH_CPU_MIPS_FAMILY 1
-#define ARCH_CPU_MIPSEL 1
-#define ARCH_CPU_32_BITS 1
-#define ARCH_CPU_LITTLE_ENDIAN 1
-#endif
-#else
-#error Please add support for your architecture in build/build_config.h
-#endif
-
-#endif  // FILESYSTEM_BUILD_CONFIG_H_
diff --git a/filesystem/filesystem/directory.cc b/filesystem/filesystem/directory.cc
deleted file mode 100644
index 0cece75..0000000
--- a/filesystem/filesystem/directory.cc
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "filesystem/directory.h"
-
-#include <limits.h>
-#include <sys/stat.h>
-#include <vector>
-
-#include "filesystem/path.h"
-#include "filesystem/portable_unistd.h"
-
-namespace filesystem {
-
-std::string GetCurrentDirectory() {
-  char buffer[PATH_MAX];
-  if (getcwd(buffer, sizeof(buffer)) == NULL) {
-    return {};
-  }
-  return std::string(buffer);
-}
-
-bool IsDirectory(const std::string& path) {
-  struct stat buf;
-  if (stat(path.c_str(), &buf) != 0)
-    return false;
-  return S_ISDIR(buf.st_mode);
-}
-
-bool CreateDirectory(const std::string& full_path) {
-  std::vector<std::string> subpaths;
-
-  // Collect a list of all parent directories.
-  std::string last_path = full_path;
-  subpaths.push_back(full_path);
-  for (std::string path = GetDirectoryName(full_path);
-       !path.empty() && path != last_path; path = GetDirectoryName(path)) {
-    subpaths.push_back(path);
-    last_path = path;
-  }
-
-  // Iterate through the parents and create the missing ones.
-  for (auto it = subpaths.rbegin(); it != subpaths.rend(); ++it) {
-    if (IsDirectory(*it))
-      continue;
-    if (mkdir(it->c_str(), 0700) == 0)
-      continue;
-    // Mkdir failed, but it might be due to the directory appearing out of thin
-    // air. This can occur if two processes are trying to create the same file
-    // system tree at the same time. Check to see if it exists and make sure it
-    // is a directory.
-    if (!IsDirectory(*it))
-      return false;
-  }
-  return true;
-}
-
-}  // namespace filesystem
diff --git a/filesystem/filesystem/directory.h b/filesystem/filesystem/directory.h
deleted file mode 100644
index 09639a2..0000000
--- a/filesystem/filesystem/directory.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef FILESYSTEM_DIRECTORY_H_
-#define FILESYSTEM_DIRECTORY_H_
-
-#include <string>
-
-namespace filesystem {
-
-// Returns the current directory. If the current directory cannot be determined,
-// this function will terminate the process.
-std::string GetCurrentDirectory();
-
-// Returns whether the given path is a directory.
-bool IsDirectory(const std::string& path);
-
-// Create a directory at the given path. If necessary, creates any intermediary
-// directory.
-bool CreateDirectory(const std::string& path);
-
-}  // namespace filesystem
-
-#endif  // FILESYSTEM_DIRECTORY_H_
diff --git a/filesystem/filesystem/eintr_wrapper.h b/filesystem/filesystem/eintr_wrapper.h
index d40c704..ef4c6ae 100644
--- a/filesystem/filesystem/eintr_wrapper.h
+++ b/filesystem/filesystem/eintr_wrapper.h
@@ -7,7 +7,7 @@
 
 #include <errno.h>
 
-#include "filesystem/build_config.h"
+#include "tonic/common/build_config.h"
 
 #if defined(OS_WIN)
 
diff --git a/filesystem/filesystem/file.cc b/filesystem/filesystem/file.cc
index 100b8cb..b4ac586 100644
--- a/filesystem/filesystem/file.cc
+++ b/filesystem/filesystem/file.cc
@@ -6,20 +6,24 @@
 
 #include <fcntl.h>
 #include <limits.h>
+#include <stdint.h>
 #include <sys/stat.h>
 
+#include "tonic/common/build_config.h"
+
 #if defined(OS_WIN)
-#define FILE_CREATE_MODE _S_IREAD | _S_IWRITE
 #define BINARY_MODE _O_BINARY
 #else
-#define FILE_CREATE_MODE 0666
 #define BINARY_MODE 0
 #endif
 
+#if defined(OS_WIN)
+#include <BaseTsd.h>
+typedef SSIZE_T ssize_t;
+#endif
+
 #include "filesystem/eintr_wrapper.h"
-#include "filesystem/file_descriptor.h"
 #include "filesystem/portable_unistd.h"
-#include "filesystem/scoped_temp_dir.h"
 
 namespace filesystem {
 namespace {
@@ -53,68 +57,6 @@
   return true;
 }
 
-}  // namespace
-
-bool WriteFile(const std::string& path, const char* data, ssize_t size) {
-  Descriptor fd(HANDLE_EINTR(creat(path.c_str(), FILE_CREATE_MODE)));
-  if (!fd.is_valid())
-    return false;
-  return WriteFileDescriptor(fd.get(), data, size);
-}
-
-bool WriteFileInTwoPhases(const std::string& path,
-                          const char* data,
-                          size_t data_len,
-                          const std::string& temp_root) {
-  ScopedTempDir temp_dir(temp_root);
-
-  std::string temp_file_path;
-  if (!temp_dir.NewTempFile(&temp_file_path)) {
-    return false;
-  }
-
-  if (!WriteFile(temp_file_path, data, data_len)) {
-    return false;
-  }
-
-  if (rename(temp_file_path.c_str(), path.c_str()) != 0) {
-    return false;
-  }
-
-  return true;
-}
-
-bool ReadFileToString(const std::string& path, std::string* result) {
-  Descriptor fd(open(path.c_str(), O_RDONLY));
-  return ReadFileDescriptor(fd.get(), result);
-}
-
-bool ReadFileDescriptorToString(int fd, std::string* result) {
-  return ReadFileDescriptor(fd, result);
-}
-
-#if defined(OS_LINUX) || defined(OS_FUCHSIA)
-bool ReadFileToStringAt(int dirfd,
-                        const std::string& path,
-                        std::string* result) {
-  Descriptor fd(openat(dirfd, path.c_str(), O_RDONLY));
-  return ReadFileDescriptor(fd.get(), result);
-}
-#endif
-
-bool ReadFileToVector(const std::string& path, std::vector<uint8_t>* result) {
-  Descriptor fd(open(path.c_str(), O_RDONLY | BINARY_MODE));
-  return ReadFileDescriptor(fd.get(), result);
-}
-
-std::pair<uint8_t*, intptr_t> ReadFileToBytes(const std::string& path) {
-  std::pair<uint8_t*, intptr_t> failure_pair{nullptr, -1};
-  Descriptor fd(open(path.c_str(), O_RDONLY | BINARY_MODE));
-  if (!fd.is_valid())
-    return failure_pair;
-  return ReadFileDescriptorToBytes(fd.get());
-}
-
 std::pair<uint8_t*, intptr_t> ReadFileDescriptorToBytes(int fd) {
   std::pair<uint8_t*, intptr_t> failure_pair{nullptr, -1};
   struct stat st;
@@ -137,28 +79,19 @@
   return std::pair<uint8_t*, intptr_t>(ptr, file_size);
 }
 
-bool IsFile(const std::string& path) {
-  struct stat buf;
-  if (stat(path.c_str(), &buf) != 0)
-    return false;
-  return S_ISREG(buf.st_mode);
+}  // namespace
+
+bool ReadFileToString(const std::string& path, std::string* result) {
+  Descriptor fd(open(path.c_str(), O_RDONLY));
+  return ReadFileDescriptor(fd.get(), result);
 }
 
-#if defined(OS_LINUX) || defined(OS_FUCHSIA)
-bool IsFileAt(int dirfd, const std::string& path) {
-  struct stat buf;
-  if (fstatat(dirfd, path.c_str(), &buf, 0 /* flags */) != 0)
-    return false;
-  return S_ISREG(buf.st_mode);
-}
-#endif
-
-bool GetFileSize(const std::string& path, uint64_t* size) {
-  struct stat stat_buffer;
-  if (stat(path.c_str(), &stat_buffer) != 0)
-    return false;
-  *size = stat_buffer.st_size;
-  return true;
+std::pair<uint8_t*, intptr_t> ReadFileToBytes(const std::string& path) {
+  std::pair<uint8_t*, intptr_t> failure_pair{nullptr, -1};
+  Descriptor fd(open(path.c_str(), O_RDONLY | BINARY_MODE));
+  if (!fd.is_valid())
+    return failure_pair;
+  return ReadFileDescriptorToBytes(fd.get());
 }
 
 }  // namespace filesystem
diff --git a/filesystem/filesystem/file.h b/filesystem/filesystem/file.h
index 08145b2..f3de866 100644
--- a/filesystem/filesystem/file.h
+++ b/filesystem/filesystem/file.h
@@ -8,56 +8,45 @@
 #include <string>
 #include <vector>
 
+#include "filesystem/eintr_wrapper.h"
+#include "filesystem/portable_unistd.h"
+
 namespace filesystem {
 
-// Writes the given data to the file at the given path. Returns true if the data
-// was successfully written, otherwise returns false.
-bool WriteFile(const std::string& path, const char* data, ssize_t size);
+class Descriptor {
+ public:
+  using Handle = int;
 
-// Writes the given data a temporary file under |temp_root| and then moves the
-// temporary file to |path|, ensuring write atomicity. Returns true if the data
-// was successfully written, otherwise returns false.
-//
-// Note that |path| and |temp_root| must be within the same filesystem for the
-// move to work. For example, it will not work to use |path| under /data and
-// |temp_root| under /tmp.
-bool WriteFileInTwoPhases(const std::string& path,
-                          const char* data,
-                          size_t data_len,
-                          const std::string& temp_root);
+  Descriptor(Handle handle) : handle_(handle) {}
+
+  ~Descriptor() {
+    if (is_valid()) {
+      IGNORE_EINTR(::close(handle_));
+    }
+  }
+
+  bool is_valid() { return handle_ >= 0; }
+
+  Handle get() { return handle_; }
+
+ private:
+  Handle handle_ = -1;
+
+  Descriptor(Descriptor&) = delete;
+
+  void operator=(const Descriptor&) = delete;
+};
 
 // Reads the contents of the file at the given path or file descriptor and
 // stores the data in result. Returns true if the file was read successfully,
 // otherwise returns false. If this function returns false, |result| will be
 // the empty string.
 bool ReadFileToString(const std::string& path, std::string* result);
-bool ReadFileDescriptorToString(int fd, std::string* result);
-
-#if defined(OS_LINUX) || defined(OS_FUCHSIA)
-bool ReadFileToStringAt(int dirfd,
-                        const std::string& path,
-                        std::string* result);
-#endif
-
-// Reads the contents of the file at the given path and stores the data in
-// result. Returns true if the file was read successfully, otherwise returns
-// false. If this function returns false, |result| will be the empty string.
-bool ReadFileToVector(const std::string& path, std::vector<uint8_t>* result);
 
 // Reads the contents of the file at the given path and if successful, returns
 // pair of read allocated bytes with data and size of the data if succesful.
 // pair of <nullptr, -1> if read failed.
 std::pair<uint8_t*, intptr_t> ReadFileToBytes(const std::string& path);
-std::pair<uint8_t*, intptr_t> ReadFileDescriptorToBytes(int fd);
-
-// Returns whether the given path is a file.
-bool IsFile(const std::string& path);
-#if defined(OS_LINUX) || defined(OS_FUCHSIA)
-bool IsFileAt(int dirfd, const std::string& path);
-#endif
-
-// If the given path is a file, set size to the size of the file.
-bool GetFileSize(const std::string& path, uint64_t* size);
 
 }  // namespace filesystem
 
diff --git a/filesystem/filesystem/file_descriptor.cc b/filesystem/filesystem/file_descriptor.cc
deleted file mode 100644
index 06ee080..0000000
--- a/filesystem/filesystem/file_descriptor.cc
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "filesystem/file_descriptor.h"
-
-#include "filesystem/eintr_wrapper.h"
-
-namespace filesystem {
-
-bool WriteFileDescriptor(int fd, const char* data, ssize_t size) {
-  ssize_t total = 0;
-  for (ssize_t partial = 0; total < size; total += partial) {
-    partial = HANDLE_EINTR(write(fd, data + total, size - total));
-    if (partial < 0)
-      return false;
-  }
-  return true;
-}
-
-ssize_t ReadFileDescriptor(int fd, char* data, ssize_t max_size) {
-  ssize_t total = 0;
-  for (ssize_t partial = 0; total < max_size; total += partial) {
-    partial = HANDLE_EINTR(read(fd, data + total, max_size - total));
-    if (partial <= 0)
-      return total ? total : partial;
-  }
-  return total;
-}
-
-}  // namespace filesystem
diff --git a/filesystem/filesystem/file_descriptor.h b/filesystem/filesystem/file_descriptor.h
deleted file mode 100644
index ad25044..0000000
--- a/filesystem/filesystem/file_descriptor.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef FILESYSTEM_FILE_DESCRIPTOR_H_
-#define FILESYSTEM_FILE_DESCRIPTOR_H_
-
-#include <unistd.h>
-
-#include "filesystem/eintr_wrapper.h"
-
-namespace filesystem {
-
-class Descriptor {
- public:
-  using Handle = int;
-
-  Descriptor(Handle handle) : handle_(handle) {}
-
-  ~Descriptor() {
-    if (is_valid()) {
-      IGNORE_EINTR(::close(handle_));
-    }
-  }
-
-  bool is_valid() { return handle_ >= 0; }
-
-  Handle get() { return handle_; }
-
- private:
-  Handle handle_ = -1;
-
-  Descriptor(Descriptor&) = delete;
-
-  void operator=(const Descriptor&) = delete;
-};
-
-bool WriteFileDescriptor(int fd, const char* data, ssize_t size);
-
-ssize_t ReadFileDescriptor(int fd, char* data, ssize_t max_size);
-
-}  // namespace filesystem
-
-#endif  // FILESYSTEM_FILE_DESCRIPTOR_H_
diff --git a/filesystem/filesystem/path.h b/filesystem/filesystem/path.h
index afe47da..1c87a35 100644
--- a/filesystem/filesystem/path.h
+++ b/filesystem/filesystem/path.h
@@ -24,9 +24,9 @@
 // to and including the last slash.
 std::string GetBaseName(const std::string& path);
 
-// Delete the file or directly at the given path. If recursive is true, and path
-// is a directory, also delete the directory's content.
-bool DeletePath(const std::string& path, bool recursive);
+// Returns the real path for the given path by unwinding symbolic links and
+// directory traversals.
+std::string GetAbsoluteFilePath(const std::string& path);
 
 }  // namespace filesystem
 
diff --git a/filesystem/filesystem/path_posix.cc b/filesystem/filesystem/path_posix.cc
index f79ebe5..a700e7d 100644
--- a/filesystem/filesystem/path_posix.cc
+++ b/filesystem/filesystem/path_posix.cc
@@ -6,6 +6,7 @@
 
 #include <dirent.h>
 #include <errno.h>
+#include <limits.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -15,7 +16,8 @@
 #include <list>
 #include <memory>
 
-#include "filesystem/directory.h"
+#include "filesystem/portable_unistd.h"
+#include "tonic/common/build_config.h"
 
 namespace filesystem {
 namespace {
@@ -32,32 +34,12 @@
   return 0;
 }
 
-void SafeCloseDir(DIR* dir) {
-  if (dir)
-    closedir(dir);
-}
-
-bool ForEachEntry(const std::string& path,
-                  std::function<bool(const std::string& path)> callback) {
-  std::unique_ptr<DIR, decltype(&SafeCloseDir)> dir(opendir(path.c_str()),
-                                                    SafeCloseDir);
-  if (!dir.get())
-    return false;
-  for (struct dirent* entry = readdir(dir.get()); entry != nullptr;
-       entry = readdir(dir.get())) {
-    char* name = entry->d_name;
-    if (name[0]) {
-      if (name[0] == '.') {
-        if (!name[1] || (name[1] == '.' && !name[2])) {
-          // . or ..
-          continue;
-        }
-      }
-      if (!callback(path + "/" + name))
-        return false;
-    }
+std::string GetCurrentDirectory() {
+  char buffer[PATH_MAX];
+  if (getcwd(buffer, sizeof(buffer)) == NULL) {
+    return {};
   }
-  return true;
+  return std::string(buffer);
 }
 
 }  // namespace
@@ -190,37 +172,16 @@
   return path.substr(separator + 1);
 }
 
-bool DeletePath(const std::string& path, bool recursive) {
-  struct stat stat_buffer;
-  if (lstat(path.c_str(), &stat_buffer) != 0)
-    return (errno == ENOENT || errno == ENOTDIR);
-  if (!S_ISDIR(stat_buffer.st_mode))
-    return (unlink(path.c_str()) == 0);
-  if (!recursive)
-    return (rmdir(path.c_str()) == 0);
-
-  // Use std::list, as ForEachEntry callback will modify the container. If the
-  // container is a vector, this will invalidate the reference to the content.
-  std::list<std::string> directories;
-  directories.push_back(path);
-  for (auto it = directories.begin(); it != directories.end(); ++it) {
-    if (!ForEachEntry(*it, [&directories](const std::string& child) {
-          if (IsDirectory(child)) {
-            directories.push_back(child);
-          } else {
-            if (unlink(child.c_str()) != 0)
-              return false;
-          }
-          return true;
-        })) {
-      return false;
-    }
-  }
-  for (auto it = directories.rbegin(); it != directories.rend(); ++it) {
-    if (rmdir(it->c_str()) != 0)
-      return false;
-  }
-  return true;
+std::string GetAbsoluteFilePath(const std::string& path) {
+#if defined(OS_FUCHSIA)
+  // realpath() isn't supported by Fuchsia. See MG-425.
+  return SimplifyPath(AbsolutePath(path));
+#else
+  char buffer[PATH_MAX];
+  if (realpath(path.c_str(), buffer) == nullptr)
+    return std::string();
+  return buffer;
+#endif  // defined(OS_FUCHSIA)
 }
 
 }  // namespace filesystem
diff --git a/filesystem/filesystem/path_win.cc b/filesystem/filesystem/path_win.cc
index fb35e75..c7da148 100644
--- a/filesystem/filesystem/path_win.cc
+++ b/filesystem/filesystem/path_win.cc
@@ -5,7 +5,6 @@
 #include "filesystem/path.h"
 
 #include <windows.h>
-#undef GetCurrentDirectory
 
 #include <direct.h>
 #include <errno.h>
@@ -19,8 +18,6 @@
 #include <list>
 #include <memory>
 
-#include "filesystem/directory.h"
-
 namespace filesystem {
 namespace {
 
@@ -206,26 +203,25 @@
   return path.substr(separator + 1);
 }
 
-bool DeletePath(const std::string& path, bool recursive) {
-  // SimplifyPath because SHFileOperation has trouble with double slashes.
-  std::string simple_path = SimplifyPath(path);
-  DWORD ftyp = GetFileAttributesA(simple_path.c_str());
-  if (ftyp == INVALID_FILE_ATTRIBUTES)
-    return false;
-  if (!(ftyp & FILE_ATTRIBUTE_DIRECTORY))
-    return (unlink(simple_path.c_str()) == 0);
-  if (!recursive)
-    return (rmdir(simple_path.c_str()) == 0);
-  SHFILEOPSTRUCTA file_op = {NULL,
-                             FO_DELETE,
-                             simple_path.c_str(),
-                             "",
-                             FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT,
-                             false,
-                             0,
-                             ""};
-  int a = SHFileOperationA(&file_op);
-  return (a == 0);
+std::string GetAbsoluteFilePath(const std::string& path) {
+  HANDLE file =
+      CreateFileA(path.c_str(), FILE_READ_ATTRIBUTES,
+                  FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
+                  OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+  if (file == INVALID_HANDLE_VALUE) {
+    return std::string();
+  }
+  char buffer[MAX_PATH];
+  DWORD ret =
+      GetFinalPathNameByHandleA(file, buffer, MAX_PATH, FILE_NAME_NORMALIZED);
+  if (ret == 0 || ret > MAX_PATH) {
+    CloseHandle(file);
+    return std::string();
+  }
+  std::string result(buffer);
+  result.erase(0, strlen("\\\\?\\"));
+  CloseHandle(file);
+  return result;
 }
 
 }  // namespace filesystem
diff --git a/filesystem/filesystem/portable_unistd.h b/filesystem/filesystem/portable_unistd.h
index 380224e..c42611e 100644
--- a/filesystem/filesystem/portable_unistd.h
+++ b/filesystem/filesystem/portable_unistd.h
@@ -5,7 +5,7 @@
 #ifndef FILESYSTEM_PORTABLE_UNISTD_H_
 #define FILESYSTEM_PORTABLE_UNISTD_H_
 
-#include "filesystem/build_config.h"
+#include "tonic/common/build_config.h"
 
 #if defined(OS_WIN)
 #include <direct.h>
diff --git a/filesystem/filesystem/scoped_temp_dir.cc b/filesystem/filesystem/scoped_temp_dir.cc
deleted file mode 100644
index 6804d4c..0000000
--- a/filesystem/filesystem/scoped_temp_dir.cc
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "filesystem/scoped_temp_dir.h"
-
-#include "filesystem/build_config.h"
-
-// mkdtemp - required include file
-#if defined(OS_MACOSX)
-#include <unistd.h>
-#elif defined(OS_WIN)
-#include <windows.h>
-#undef CreateDirectory
-#include "filesystem/file.h"
-#else
-#include <stdlib.h>
-#endif
-
-#include "filesystem/directory.h"
-#include "filesystem/file_descriptor.h"
-#include "filesystem/path.h"
-
-namespace filesystem {
-
-ScopedTempDir::ScopedTempDir() = default;
-
-ScopedTempDir::ScopedTempDir(std::string parent_path) {
-#if defined(OS_WIN)
-  if (parent_path.empty()) {
-    char buffer[MAX_PATH];
-    DWORD ret = GetTempPathA(MAX_PATH, buffer);
-    if (ret > MAX_PATH || (ret == 0)) {
-      directory_path_ = "";
-      return;
-    }
-    parent_path = {buffer};
-  }
-  do {
-    directory_path_ = parent_path.ToString() + "\\" + fxl::GenerateUUID();
-  } while (IsFile(directory_path_) || IsDirectory(directory_path_));
-  if (!CreateDirectory(directory_path_)) {
-    directory_path_ = "";
-  }
-#else
-  if (parent_path.empty()) {
-    const char* env_var = getenv("TMPDIR");
-    parent_path = env_var ? std::string{env_var} : "/tmp";
-  }
-  // mkdtemp replaces "XXXXXX" so that the resulting directory path is unique.
-  directory_path_ = parent_path + "/temp_dir_XXXXXX";
-  if (!CreateDirectory(parent_path) || !mkdtemp(&directory_path_[0])) {
-    directory_path_ = "";
-  }
-#endif
-}
-
-ScopedTempDir::~ScopedTempDir() {
-  if (directory_path_.size()) {
-    DeletePath(directory_path_, true);
-  }
-}
-
-const std::string& ScopedTempDir::path() {
-  return directory_path_;
-}
-
-bool ScopedTempDir::NewTempFile(std::string* output) {
-#if defined(OS_WIN)
-  char buffer[MAX_PATH];
-  UINT ret = GetTempFileNameA(directory_path_.c_str(), "", 0, buffer);
-  output->swap(std::string(buffer));
-  return (ret != 0);
-#else
-  // mkstemp replaces "XXXXXX" so that the resulting file path is unique.
-  std::string file_path = directory_path_ + "/XXXXXX";
-  filesystem::Descriptor fd(mkstemp(&file_path[0]));
-  if (!fd.is_valid()) {
-    return false;
-  }
-  output->swap(file_path);
-  return true;
-#endif
-}
-
-}  // namespace filesystem
diff --git a/filesystem/filesystem/scoped_temp_dir.h b/filesystem/filesystem/scoped_temp_dir.h
deleted file mode 100644
index 5a3b27d..0000000
--- a/filesystem/filesystem/scoped_temp_dir.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef FILESYSTEM_SCOPED_TEMP_DIR_H_
-#define FILESYSTEM_SCOPED_TEMP_DIR_H_
-
-#include <string>
-
-namespace filesystem {
-
-class ScopedTempDir {
- public:
-  ScopedTempDir();
-
-  explicit ScopedTempDir(std::string parent_path);
-
-  ~ScopedTempDir();
-
-  const std::string& path();
-
-  bool NewTempFile(std::string* output);
-
- private:
-  std::string directory_path_;
-};
-
-}  // namespace filesystem
-
-#endif  // FILESYSTEM_SCOPED_TEMP_DIR_H_
diff --git a/filesystem/filesystem/symlink.h b/filesystem/filesystem/symlink.h
deleted file mode 100644
index db9a39b..0000000
--- a/filesystem/filesystem/symlink.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef FILESYSTEM_SYMLINK_H_
-#define FILESYSTEM_SYMLINK_H_
-
-#include <string>
-
-namespace filesystem {
-
-// If |path| is a symbolic link, this function will return true and set
-// |resolved_path| to the path pointed to by the symbolic link. Otherwise,
-// this function will return false and |resolved_path| will be the empty string.
-bool ReadSymbolicLink(const std::string& path, std::string* resolved_path);
-
-// Returns the real path for the given path by unwinding symbolic links and
-// directory traversals.
-std::string GetAbsoluteFilePath(const std::string& path);
-
-}  // namespace filesystem
-
-#endif  // FILESYSTEM_SYMLINK_H_
diff --git a/filesystem/filesystem/symlink_posix.cc b/filesystem/filesystem/symlink_posix.cc
deleted file mode 100644
index 691264d..0000000
--- a/filesystem/filesystem/symlink_posix.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "filesystem/symlink.h"
-
-#include <limits.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "filesystem/build_config.h"
-#include "filesystem/path.h"
-
-namespace filesystem {
-
-bool ReadSymbolicLink(const std::string& path, std::string* resolved_path) {
-  if (path.empty() || resolved_path == nullptr) {
-    return false;
-  }
-
-  char buffer[PATH_MAX];
-  ssize_t length = readlink(path.c_str(), buffer, sizeof(buffer));
-
-  if (length <= 0) {
-    resolved_path->clear();
-    return false;
-  }
-
-  *resolved_path = std::string(buffer, length);
-  return true;
-}
-
-std::string GetAbsoluteFilePath(const std::string& path) {
-#if defined(OS_FUCHSIA)
-  // realpath() isn't supported by Fuchsia. See MG-425.
-  return SimplifyPath(AbsolutePath(path));
-#else
-  char buffer[PATH_MAX];
-  if (realpath(path.c_str(), buffer) == nullptr)
-    return std::string();
-  return buffer;
-#endif  // defined(OS_FUCHSIA)
-}
-
-}  // namespace filesystem
diff --git a/filesystem/filesystem/symlink_win.cc b/filesystem/filesystem/symlink_win.cc
deleted file mode 100644
index d9db2e5..0000000
--- a/filesystem/filesystem/symlink_win.cc
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2017 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "filesystem/symlink.h"
-
-#include <windows.h>
-#include <winioctl.h>
-
-#include <iostream>
-
-namespace filesystem {
-
-struct UniqueHandleTraits {
-  static HANDLE InvalidValue() { return INVALID_HANDLE_VALUE; }
-  static bool IsValid(HANDLE value) { return value != INVALID_HANDLE_VALUE; }
-  static void Free(HANDLE value) { CloseHandle(value); }
-};
-
-bool ReadSymbolicLink(const std::string& path, std::string* resolved_path) {
-  FXL_CHECK(false) << "Unimplemented";
-  return false;
-}
-
-std::string GetAbsoluteFilePath(const std::string& path) {
-  fxl::UniqueObject<HANDLE, UniqueHandleTraits> file(
-      CreateFileA(path.c_str(), FILE_READ_ATTRIBUTES,
-                  FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
-                  OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL));
-  if (!file.is_valid()) {
-    return std::string();
-  }
-  char buffer[MAX_PATH];
-  DWORD ret = GetFinalPathNameByHandleA(file.get(), buffer, MAX_PATH,
-                                        FILE_NAME_NORMALIZED);
-  if (ret == 0 || ret > MAX_PATH) {
-    return std::string();
-  }
-  std::string result(buffer);
-  result.erase(0, strlen("\\\\?\\"));
-  return result;
-}
-
-}  // namespace filesystem
diff --git a/filesystem/tests/file_descriptor_unittest.cc b/filesystem/tests/file_descriptor_unittest.cc
index 23470ae..efb844f 100644
--- a/filesystem/tests/file_descriptor_unittest.cc
+++ b/filesystem/tests/file_descriptor_unittest.cc
@@ -2,7 +2,6 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "filesystem/file_descriptor.h"
 #include "lib/fxl/portable_unistd.h"
 
 #include <fcntl.h>
diff --git a/filesystem/tests/path_unittest.cc b/filesystem/tests/path_unittest.cc
index 1d281e3..d5e9d85 100644
--- a/filesystem/tests/path_unittest.cc
+++ b/filesystem/tests/path_unittest.cc
@@ -3,10 +3,10 @@
 // found in the LICENSE file.
 
 #include "filesystem/path.h"
-#include "filesystem/build_config.h"
 #include "filesystem/directory.h"
 #include "filesystem/scoped_temp_dir.h"
 #include "gtest/gtest.h"
+#include "tonic/common/build_config.h"
 
 namespace filesystem {