diff --git a/contrib/kyua/utils/fs/operations.cpp b/contrib/kyua/utils/fs/operations.cpp index 7a96d0b2058a..185d164b88d7 100644 --- a/contrib/kyua/utils/fs/operations.cpp +++ b/contrib/kyua/utils/fs/operations.cpp @@ -1,803 +1,805 @@ // Copyright 2010 The Kyua Authors. // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of Google Inc. nor the names of its contributors // may be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "utils/fs/operations.hpp" #if defined(HAVE_CONFIG_H) # include "config.h" #endif extern "C" { #include #if defined(HAVE_SYS_MOUNT_H) # include #endif #include #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) # include #endif #if defined(HAVE_SYS_VFS_H) # include #endif #include #include } #include #include #include #include #include #include #include #include "utils/auto_array.ipp" #include "utils/defs.hpp" #include "utils/env.hpp" #include "utils/format/macros.hpp" #include "utils/fs/directory.hpp" #include "utils/fs/exceptions.hpp" #include "utils/fs/path.hpp" #include "utils/logging/macros.hpp" #include "utils/optional.ipp" #include "utils/sanity.hpp" #include "utils/units.hpp" namespace fs = utils::fs; namespace units = utils::units; using utils::optional; namespace { /// Operating systems recognized by the code below. enum os_type { os_unsupported = 0, os_freebsd, os_linux, os_netbsd, os_sunos, }; /// The current operating system. static enum os_type current_os = #if defined(__FreeBSD__) os_freebsd #elif defined(__linux__) os_linux #elif defined(__NetBSD__) os_netbsd #elif defined(__SunOS__) os_sunos #else os_unsupported #endif ; /// Specifies if a real unmount(2) is available. /// /// We use this as a constant instead of a macro so that we can compile both /// versions of the unmount code unconditionally. This is a way to prevent /// compilation bugs going unnoticed for long. static const bool have_unmount2 = #if defined(HAVE_UNMOUNT) true; #else false; #endif #if !defined(UMOUNT) /// Fake replacement value to the path to umount(8). # define UMOUNT "do-not-use-this-value" #else # if defined(HAVE_UNMOUNT) # error "umount(8) detected when unmount(2) is also available" # endif #endif #if !defined(HAVE_UNMOUNT) /// Fake unmount(2) function for systems without it. /// /// This is only provided to allow our code to compile in all platforms /// regardless of whether they actually have an unmount(2) or not. /// /// \return -1 to indicate error, although this should never happen. static int unmount(const char* /* path */, const int /* flags */) { PRE(false); return -1; } #endif /// Error code returned by subprocess to indicate a controlled failure. const int exit_known_error = 123; static void run_mount_tmpfs(const fs::path&, const uint64_t) UTILS_NORETURN; /// Executes 'mount -t tmpfs' (or a similar variant). /// /// This function must be called from a subprocess as it never returns. /// /// \param mount_point Location on which to mount a tmpfs. /// \param size The size of the tmpfs to mount. If 0, use unlimited. static void run_mount_tmpfs(const fs::path& mount_point, const uint64_t size) { const char* mount_args[16]; std::string size_arg; std::size_t last = 0; switch (current_os) { case os_freebsd: mount_args[last++] = "mount"; mount_args[last++] = "-ttmpfs"; if (size > 0) { size_arg = F("-osize=%s") % size; mount_args[last++] = size_arg.c_str(); } mount_args[last++] = "tmpfs"; mount_args[last++] = mount_point.c_str(); break; case os_linux: mount_args[last++] = "mount"; mount_args[last++] = "-ttmpfs"; if (size > 0) { size_arg = F("-osize=%s") % size; mount_args[last++] = size_arg.c_str(); } mount_args[last++] = "tmpfs"; mount_args[last++] = mount_point.c_str(); break; case os_netbsd: mount_args[last++] = "mount"; mount_args[last++] = "-ttmpfs"; if (size > 0) { size_arg = F("-o-s%s") % size; mount_args[last++] = size_arg.c_str(); } mount_args[last++] = "tmpfs"; mount_args[last++] = mount_point.c_str(); break; case os_sunos: mount_args[last++] = "mount"; mount_args[last++] = "-Ftmpfs"; if (size > 0) { size_arg = F("-o-s%s") % size; mount_args[last++] = size_arg.c_str(); } mount_args[last++] = "tmpfs"; mount_args[last++] = mount_point.c_str(); break; default: std::cerr << "Don't know how to mount a temporary file system in this " "host operating system\n"; std::exit(exit_known_error); } mount_args[last] = NULL; const char** arg; std::cout << "Mounting tmpfs onto " << mount_point << " with:"; for (arg = &mount_args[0]; *arg != NULL; arg++) std::cout << " " << *arg; std::cout << "\n"; const int ret = ::execvp(mount_args[0], UTILS_UNCONST(char* const, mount_args)); INV(ret == -1); std::cerr << "Failed to exec " << mount_args[0] << "\n"; std::exit(EXIT_FAILURE); } /// Unmounts a file system using unmount(2). /// /// \pre unmount(2) must be available; i.e. have_unmount2 must be true. /// /// \param mount_point The file system to unmount. /// /// \throw fs::system_error If the call to unmount(2) fails. static void unmount_with_unmount2(const fs::path& mount_point) { PRE(have_unmount2); if (::unmount(mount_point.c_str(), 0) == -1) { const int original_errno = errno; throw fs::system_error(F("unmount(%s) failed") % mount_point, original_errno); } } /// Unmounts a file system using umount(8). /// /// \pre umount(2) must not be available; i.e. have_unmount2 must be false. /// /// \param mount_point The file system to unmount. /// /// \throw fs::error If the execution of umount(8) fails. static void unmount_with_umount8(const fs::path& mount_point) { PRE(!have_unmount2); const pid_t pid = ::fork(); if (pid == -1) { const int original_errno = errno; throw fs::system_error("Cannot fork to execute unmount tool", original_errno); } else if (pid == 0) { const int ret = ::execlp(UMOUNT, "umount", mount_point.c_str(), NULL); INV(ret == -1); std::cerr << "Failed to exec " UMOUNT "\n"; std::exit(EXIT_FAILURE); } int status; retry: if (::waitpid(pid, &status, 0) == -1) { const int original_errno = errno; if (errno == EINTR) goto retry; throw fs::system_error("Failed to wait for unmount subprocess", original_errno); } if (WIFEXITED(status)) { if (WEXITSTATUS(status) == EXIT_SUCCESS) return; else throw fs::error(F("Failed to unmount %s; returned exit code %s") % mount_point % WEXITSTATUS(status)); } else throw fs::error(F("Failed to unmount %s; unmount tool received signal") % mount_point); } /// Stats a file, without following links. /// /// \param path The file to stat. /// /// \return The stat structure on success. /// /// \throw system_error An error on failure. static struct ::stat safe_stat(const fs::path& path) { struct ::stat sb; if (::lstat(path.c_str(), &sb) == -1) { const int original_errno = errno; throw fs::system_error(F("Cannot get information about %s") % path, original_errno); } return sb; } } // anonymous namespace /// Copies a file. /// /// \param source The file to copy. /// \param target The destination of the new copy; must be a file name, not a /// directory. /// /// \throw error If there is a problem copying the file. void fs::copy(const fs::path& source, const fs::path& target) { std::ifstream input(source.c_str()); if (!input) throw error(F("Cannot open copy source %s") % source); std::ofstream output(target.c_str()); if (!output) throw error(F("Cannot create copy target %s") % target); char buffer[1024]; while (input.good()) { input.read(buffer, sizeof(buffer)); if (input.good() || input.eof()) output.write(buffer, input.gcount()); } if (!input.good() && !input.eof()) throw error(F("Error while reading input file %s") % source); } /// Queries the path to the current directory. /// /// \return The path to the current directory. /// /// \throw fs::error If there is a problem querying the current directory. fs::path fs::current_path(void) { char* cwd; #if defined(HAVE_GETCWD_DYN) cwd = ::getcwd(NULL, 0); #else cwd = ::getcwd(NULL, MAXPATHLEN); #endif if (cwd == NULL) { const int original_errno = errno; throw fs::system_error(F("Failed to get current working directory"), original_errno); } try { const fs::path result(cwd); std::free(cwd); return result; } catch (...) { std::free(cwd); throw; } } /// Checks if a file exists. /// /// Be aware that this is racy in the same way as access(2) is. /// /// \param path The file to check the existance of. /// /// \return True if the file exists; false otherwise. bool fs::exists(const fs::path& path) { return ::access(path.c_str(), F_OK) == 0; } /// Locates a file in the PATH. /// /// \param name The file to locate. /// /// \return The path to the located file or none if it was not found. The /// returned path is always absolute. optional< fs::path > fs::find_in_path(const char* name) { const optional< std::string > current_path = utils::getenv("PATH"); if (!current_path || current_path.get().empty()) return none; std::istringstream path_input(current_path.get() + ":"); std::string path_component; while (std::getline(path_input, path_component, ':').good()) { const fs::path candidate = path_component.empty() ? fs::path(name) : (fs::path(path_component) / name); if (exists(candidate)) { if (candidate.is_absolute()) return utils::make_optional(candidate); else return utils::make_optional(candidate.to_absolute()); } } return none; } /// Calculates the free space in a given file system. /// /// \param path Path to a file in the file system for which to check the free /// disk space. /// /// \return The amount of free space usable by a non-root user. /// /// \throw system_error If the call to statfs(2) fails. utils::units::bytes fs::free_disk_space(const fs::path& path) { #if defined(HAVE_STATVFS) struct ::statvfs buf; if (::statvfs(path.c_str(), &buf) == -1) { const int original_errno = errno; throw fs::system_error(F("Failed to stat file system for %s") % path, original_errno); } return units::bytes(uint64_t(buf.f_bsize) * buf.f_bavail); #elif defined(HAVE_STATFS) struct ::statfs buf; if (::statfs(path.c_str(), &buf) == -1) { const int original_errno = errno; throw fs::system_error(F("Failed to stat file system for %s") % path, original_errno); } return units::bytes(uint64_t(buf.f_bsize) * buf.f_bavail); #else # error "Don't know how to query free disk space" #endif } /// Checks if the given path is a directory or not. /// /// \return True if the path is a directory; false otherwise. bool fs::is_directory(const fs::path& path) { const struct ::stat sb = safe_stat(path); return S_ISDIR(sb.st_mode); } /// Creates a directory. /// /// \param dir The path to the directory to create. /// \param mode The permissions for the new directory. /// /// \throw system_error If the call to mkdir(2) fails. void fs::mkdir(const fs::path& dir, const int mode) { if (::mkdir(dir.c_str(), static_cast< mode_t >(mode)) == -1) { const int original_errno = errno; throw fs::system_error(F("Failed to create directory %s") % dir, original_errno); } } /// Creates a directory and any missing parents. /// /// This is separate from the fs::mkdir function to clearly differentiate the /// libc wrapper from the more complex algorithm implemented here. /// /// \param dir The path to the directory to create. /// \param mode The permissions for the new directories. /// /// \throw system_error If any call to mkdir(2) fails. void fs::mkdir_p(const fs::path& dir, const int mode) { try { fs::mkdir(dir, mode); } catch (const fs::system_error& e) { if (e.original_errno() == ENOENT) { fs::mkdir_p(dir.branch_path(), mode); fs::mkdir(dir, mode); } else if (e.original_errno() != EEXIST) throw e; } } /// Creates a temporary directory that is world readable/accessible. /// /// The temporary directory is created using mkdtemp(3) using the provided /// template. This should be most likely used in conjunction with /// fs::auto_directory. /// /// The temporary directory is given read and execute permissions to everyone /// and thus should not be used to protect data that may be subject to snooping. /// This goes together with the assumption that this function is used to create /// temporary directories for test cases, and that those test cases may /// sometimes be executed as an unprivileged user. In those cases, we need to /// support two different things: /// /// - Allow the unprivileged code to write to files in the work directory by /// name (e.g. to write the results file, whose name is provided by the /// monitor code running as root). This requires us to grant search /// permissions. /// /// - Allow the test cases themselves to call getcwd(3) at any point. At least /// on NetBSD 7.x, getcwd(3) requires both read and search permissions on all /// path components leading to the current directory. This requires us to /// grant both read and search permissions. /// /// TODO(jmmv): A cleaner way to support this would be for the test executor to /// create two work directory hierarchies directly rooted under TMPDIR: one for /// root and one for the unprivileged user. However, that requires more /// bookkeeping for no real gain, because we are not really trying to protect /// the data within our temporary directories against attacks. /// /// \param path_template The template for the temporary path, which is a /// basename that is created within the TMPDIR. Must contain the XXXXXX /// pattern, which is atomically replaced by a random unique string. /// /// \return The generated path for the temporary directory. /// /// \throw fs::system_error If the call to mkdtemp(3) fails. fs::path fs::mkdtemp_public(const std::string& path_template) { PRE(path_template.find("XXXXXX") != std::string::npos); const fs::path tmpdir(utils::getenv_with_default("TMPDIR", "/tmp")); const fs::path full_template = tmpdir / path_template; utils::auto_array< char > buf(new char[full_template.str().length() + 1]); std::strcpy(buf.get(), full_template.c_str()); if (::mkdtemp(buf.get()) == NULL) { const int original_errno = errno; throw fs::system_error(F("Cannot create temporary directory using " "template %s") % full_template, original_errno); } const fs::path path(buf.get()); if (::chmod(path.c_str(), 0755) == -1) { const int original_errno = errno; try { rmdir(path); } catch (const fs::system_error& e) { // This really should not fail. We just created the directory and // have not written anything to it so there is no reason for this to // fail. But better handle the failure just in case. LW(F("Failed to delete just-created temporary directory %s") % path); } throw fs::system_error(F("Failed to grant search permissions on " "temporary directory %s") % path, original_errno); } return path; } /// Creates a temporary file. /// /// The temporary file is created using mkstemp(3) using the provided template. /// This should be most likely used in conjunction with fs::auto_file. /// /// \param path_template The template for the temporary path, which is a /// basename that is created within the TMPDIR. Must contain the XXXXXX /// pattern, which is atomically replaced by a random unique string. /// /// \return The generated path for the temporary directory. /// /// \throw fs::system_error If the call to mkstemp(3) fails. fs::path fs::mkstemp(const std::string& path_template) { PRE(path_template.find("XXXXXX") != std::string::npos); const fs::path tmpdir(utils::getenv_with_default("TMPDIR", "/tmp")); const fs::path full_template = tmpdir / path_template; utils::auto_array< char > buf(new char[full_template.str().length() + 1]); std::strcpy(buf.get(), full_template.c_str()); if (::mkstemp(buf.get()) == -1) { const int original_errno = errno; throw fs::system_error(F("Cannot create temporary file using template " "%s") % full_template, original_errno); } return fs::path(buf.get()); } /// Mounts a temporary file system with unlimited size. /// /// \param in_mount_point The path on which the file system will be mounted. /// /// \throw fs::system_error If the attempt to mount process fails. /// \throw fs::unsupported_operation_error If the code does not know how to /// mount a temporary file system in the current operating system. void fs::mount_tmpfs(const fs::path& in_mount_point) { mount_tmpfs(in_mount_point, units::bytes()); } /// Mounts a temporary file system. /// /// \param in_mount_point The path on which the file system will be mounted. /// \param size The size of the tmpfs to mount. If 0, use unlimited. /// /// \throw fs::system_error If the attempt to mount process fails. /// \throw fs::unsupported_operation_error If the code does not know how to /// mount a temporary file system in the current operating system. void fs::mount_tmpfs(const fs::path& in_mount_point, const units::bytes& size) { // SunOS's mount(8) requires paths to be absolute. To err on the side of // caution, let's make the mount point absolute in all cases. const fs::path mount_point = in_mount_point.is_absolute() ? in_mount_point : in_mount_point.to_absolute(); const pid_t pid = ::fork(); if (pid == -1) { const int original_errno = errno; throw fs::system_error("Cannot fork to execute mount tool", original_errno); } if (pid == 0) run_mount_tmpfs(mount_point, size); int status; retry: if (::waitpid(pid, &status, 0) == -1) { const int original_errno = errno; if (errno == EINTR) goto retry; throw fs::system_error("Failed to wait for mount subprocess", original_errno); } if (WIFEXITED(status)) { if (WEXITSTATUS(status) == exit_known_error) throw fs::unsupported_operation_error( "Don't know how to mount a tmpfs on this operating system"); else if (WEXITSTATUS(status) == EXIT_SUCCESS) return; else throw fs::error(F("Failed to mount tmpfs on %s; returned exit " "code %s") % mount_point % WEXITSTATUS(status)); } else { throw fs::error(F("Failed to mount tmpfs on %s; mount tool " "received signal") % mount_point); } } /// Recursively removes a directory. /// /// This operation simulates a "rm -r". No effort is made to forcibly delete /// files and no attention is paid to mount points. /// /// \param directory The directory to remove. /// /// \throw fs::error If there is a problem removing any directory or file. void fs::rm_r(const fs::path& directory) { const fs::directory dir(directory); + ::chmod(directory.c_str(), 0700); for (fs::directory::const_iterator iter = dir.begin(); iter != dir.end(); ++iter) { if (iter->name == "." || iter->name == "..") continue; const fs::path entry = directory / iter->name; if (fs::is_directory(entry)) { LD(F("Descending into %s") % entry); + ::chmod(entry.c_str(), 0700); fs::rm_r(entry); } else { LD(F("Removing file %s") % entry); fs::unlink(entry); } } LD(F("Removing empty directory %s") % directory); fs::rmdir(directory); } /// Removes an empty directory. /// /// \param file The directory to remove. /// /// \throw fs::system_error If the call to rmdir(2) fails. void fs::rmdir(const path& file) { if (::rmdir(file.c_str()) == -1) { const int original_errno = errno; throw fs::system_error(F("Removal of %s failed") % file, original_errno); } } /// Obtains all the entries in a directory. /// /// \param path The directory to scan. /// /// \return The set of all directory entries in the given directory. /// /// \throw fs::system_error If reading the directory fails for any reason. std::set< fs::directory_entry > fs::scan_directory(const fs::path& path) { std::set< fs::directory_entry > contents; fs::directory dir(path); for (fs::directory::const_iterator iter = dir.begin(); iter != dir.end(); ++iter) { contents.insert(*iter); } return contents; } /// Removes a file. /// /// \param file The file to remove. /// /// \throw fs::system_error If the call to unlink(2) fails. void fs::unlink(const path& file) { if (::unlink(file.c_str()) == -1) { const int original_errno = errno; throw fs::system_error(F("Removal of %s failed") % file, original_errno); } } /// Unmounts a file system. /// /// \param in_mount_point The file system to unmount. /// /// \throw fs::error If the unmount fails. void fs::unmount(const fs::path& in_mount_point) { // FreeBSD's unmount(2) requires paths to be absolute. To err on the side // of caution, let's make it absolute in all cases. const fs::path mount_point = in_mount_point.is_absolute() ? in_mount_point : in_mount_point.to_absolute(); static const int unmount_retries = 3; static const int unmount_retry_delay_seconds = 1; int retries = unmount_retries; retry: try { if (have_unmount2) { unmount_with_unmount2(mount_point); } else { unmount_with_umount8(mount_point); } } catch (const fs::system_error& error) { if (error.original_errno() == EBUSY && retries > 0) { LW(F("%s busy; unmount retries left %s") % mount_point % retries); retries--; ::sleep(unmount_retry_delay_seconds); goto retry; } throw; } } diff --git a/contrib/kyua/utils/fs/operations_test.cpp b/contrib/kyua/utils/fs/operations_test.cpp index f1349351166e..6f0fa52811c9 100644 --- a/contrib/kyua/utils/fs/operations_test.cpp +++ b/contrib/kyua/utils/fs/operations_test.cpp @@ -1,826 +1,840 @@ // Copyright 2010 The Kyua Authors. // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of Google Inc. nor the names of its contributors // may be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "utils/fs/operations.hpp" extern "C" { #include #include #include #include #include #include } #include #include #include #include #include #include #include #include #include "utils/env.hpp" #include "utils/format/containers.ipp" #include "utils/format/macros.hpp" #include "utils/fs/directory.hpp" #include "utils/fs/exceptions.hpp" #include "utils/fs/path.hpp" #include "utils/optional.ipp" #include "utils/passwd.hpp" #include "utils/stream.hpp" #include "utils/units.hpp" namespace fs = utils::fs; namespace passwd = utils::passwd; namespace units = utils::units; using utils::optional; namespace { /// Checks if a directory entry exists and matches a specific type. /// /// \param dir The directory in which to look for the entry. /// \param name The name of the entry to look up. /// \param expected_type The expected type of the file as given by dir(5). /// /// \return True if the entry exists and matches the given type; false /// otherwise. static bool lookup(const char* dir, const char* name, const unsigned int expected_type) { DIR* dirp = ::opendir(dir); ATF_REQUIRE(dirp != NULL); bool found = false; struct dirent* dp; while (!found && (dp = readdir(dirp)) != NULL) { if (std::strcmp(dp->d_name, name) == 0) { struct ::stat s; const fs::path lookup_path = fs::path(dir) / name; ATF_REQUIRE(::stat(lookup_path.c_str(), &s) != -1); if ((s.st_mode & S_IFMT) == expected_type) { found = true; } } } ::closedir(dirp); return found; } } // anonymous namespace ATF_TEST_CASE_WITHOUT_HEAD(copy__ok); ATF_TEST_CASE_BODY(copy__ok) { const fs::path source("f1.txt"); const fs::path target("f2.txt"); atf::utils::create_file(source.str(), "This is the input"); fs::copy(source, target); ATF_REQUIRE(atf::utils::compare_file(target.str(), "This is the input")); } ATF_TEST_CASE_WITHOUT_HEAD(copy__fail_open); ATF_TEST_CASE_BODY(copy__fail_open) { const fs::path source("f1.txt"); const fs::path target("f2.txt"); ATF_REQUIRE_THROW_RE(fs::error, "Cannot open copy source f1.txt", fs::copy(source, target)); } ATF_TEST_CASE(copy__fail_create); ATF_TEST_CASE_HEAD(copy__fail_create) { set_md_var("require.user", "unprivileged"); } ATF_TEST_CASE_BODY(copy__fail_create) { const fs::path source("f1.txt"); const fs::path target("f2.txt"); atf::utils::create_file(target.str(), "Do not override"); ATF_REQUIRE(::chmod(target.c_str(), 0444) != -1); atf::utils::create_file(source.str(), "This is the input"); ATF_REQUIRE_THROW_RE(fs::error, "Cannot create copy target f2.txt", fs::copy(source, target)); } ATF_TEST_CASE_WITHOUT_HEAD(current_path__ok); ATF_TEST_CASE_BODY(current_path__ok) { const fs::path previous = fs::current_path(); fs::mkdir(fs::path("root"), 0755); ATF_REQUIRE(::chdir("root") != -1); const fs::path cwd = fs::current_path(); ATF_REQUIRE_EQ(cwd.str().length() - 5, cwd.str().find("/root")); ATF_REQUIRE_EQ(previous / "root", cwd); } ATF_TEST_CASE_WITHOUT_HEAD(current_path__enoent); ATF_TEST_CASE_BODY(current_path__enoent) { const fs::path previous = fs::current_path(); fs::mkdir(fs::path("root"), 0755); ATF_REQUIRE(::chdir("root") != -1); ATF_REQUIRE(::rmdir("../root") != -1); try { (void)fs::current_path(); fail("system_errpr not raised"); } catch (const fs::system_error& e) { ATF_REQUIRE_EQ(ENOENT, e.original_errno()); } } ATF_TEST_CASE_WITHOUT_HEAD(exists); ATF_TEST_CASE_BODY(exists) { const fs::path dir("dir"); ATF_REQUIRE(!fs::exists(dir)); fs::mkdir(dir, 0755); ATF_REQUIRE(fs::exists(dir)); } ATF_TEST_CASE_WITHOUT_HEAD(find_in_path__no_path); ATF_TEST_CASE_BODY(find_in_path__no_path) { utils::unsetenv("PATH"); ATF_REQUIRE(!fs::find_in_path("ls")); atf::utils::create_file("ls", ""); ATF_REQUIRE(!fs::find_in_path("ls")); } ATF_TEST_CASE_WITHOUT_HEAD(find_in_path__empty_path); ATF_TEST_CASE_BODY(find_in_path__empty_path) { utils::setenv("PATH", ""); ATF_REQUIRE(!fs::find_in_path("ls")); atf::utils::create_file("ls", ""); ATF_REQUIRE(!fs::find_in_path("ls")); } ATF_TEST_CASE_WITHOUT_HEAD(find_in_path__one_component); ATF_TEST_CASE_BODY(find_in_path__one_component) { const fs::path dir = fs::current_path() / "bin"; fs::mkdir(dir, 0755); utils::setenv("PATH", dir.str()); ATF_REQUIRE(!fs::find_in_path("ls")); atf::utils::create_file((dir / "ls").str(), ""); ATF_REQUIRE_EQ(dir / "ls", fs::find_in_path("ls").get()); } ATF_TEST_CASE_WITHOUT_HEAD(find_in_path__many_components); ATF_TEST_CASE_BODY(find_in_path__many_components) { const fs::path dir1 = fs::current_path() / "dir1"; const fs::path dir2 = fs::current_path() / "dir2"; fs::mkdir(dir1, 0755); fs::mkdir(dir2, 0755); utils::setenv("PATH", dir1.str() + ":" + dir2.str()); ATF_REQUIRE(!fs::find_in_path("ls")); atf::utils::create_file((dir2 / "ls").str(), ""); ATF_REQUIRE_EQ(dir2 / "ls", fs::find_in_path("ls").get()); atf::utils::create_file((dir1 / "ls").str(), ""); ATF_REQUIRE_EQ(dir1 / "ls", fs::find_in_path("ls").get()); } ATF_TEST_CASE_WITHOUT_HEAD(find_in_path__current_directory); ATF_TEST_CASE_BODY(find_in_path__current_directory) { utils::setenv("PATH", "bin:"); ATF_REQUIRE(!fs::find_in_path("foo-bar")); atf::utils::create_file("foo-bar", ""); ATF_REQUIRE_EQ(fs::path("foo-bar").to_absolute(), fs::find_in_path("foo-bar").get()); } ATF_TEST_CASE_WITHOUT_HEAD(find_in_path__always_absolute); ATF_TEST_CASE_BODY(find_in_path__always_absolute) { fs::mkdir(fs::path("my-bin"), 0755); utils::setenv("PATH", "my-bin"); ATF_REQUIRE(!fs::find_in_path("abcd")); atf::utils::create_file("my-bin/abcd", ""); ATF_REQUIRE_EQ(fs::path("my-bin/abcd").to_absolute(), fs::find_in_path("abcd").get()); } ATF_TEST_CASE_WITHOUT_HEAD(free_disk_space__ok__smoke); ATF_TEST_CASE_BODY(free_disk_space__ok__smoke) { const units::bytes space = fs::free_disk_space(fs::path(".")); ATF_REQUIRE(space > units::MB); // Simple test that should always pass. } /// Unmounts a directory without raising errors. /// /// \param cookie Name of a file that exists while the mount point is still /// mounted. Used to prevent a double-unmount, which would print a /// misleading error message. /// \param mount_point Path to the mount point to unmount. static void cleanup_mount_point(const fs::path& cookie, const fs::path& mount_point) { try { if (fs::exists(cookie)) { fs::unmount(mount_point); } } catch (const std::runtime_error& e) { std::cerr << "Failed trying to unmount " + mount_point.str() + " during cleanup: " << e.what() << '\n'; } } ATF_TEST_CASE_WITH_CLEANUP(free_disk_space__ok__real); ATF_TEST_CASE_HEAD(free_disk_space__ok__real) { set_md_var("require.user", "root"); } ATF_TEST_CASE_BODY(free_disk_space__ok__real) { try { const fs::path mount_point("mount_point"); fs::mkdir(mount_point, 0755); fs::mount_tmpfs(mount_point, units::bytes(32 * units::MB)); atf::utils::create_file("mounted", ""); const units::bytes space = fs::free_disk_space(fs::path(mount_point)); fs::unmount(mount_point); fs::unlink(fs::path("mounted")); ATF_REQUIRE(space < 35 * units::MB); ATF_REQUIRE(space > 28 * units::MB); } catch (const fs::unsupported_operation_error& e) { ATF_SKIP(e.what()); } } ATF_TEST_CASE_CLEANUP(free_disk_space__ok__real) { cleanup_mount_point(fs::path("mounted"), fs::path("mount_point")); } ATF_TEST_CASE_WITHOUT_HEAD(free_disk_space__fail); ATF_TEST_CASE_BODY(free_disk_space__fail) { ATF_REQUIRE_THROW_RE(fs::error, "Failed to stat file system for missing", fs::free_disk_space(fs::path("missing"))); } ATF_TEST_CASE_WITHOUT_HEAD(is_directory__ok); ATF_TEST_CASE_BODY(is_directory__ok) { const fs::path file("file"); atf::utils::create_file(file.str(), ""); ATF_REQUIRE(!fs::is_directory(file)); const fs::path dir("dir"); fs::mkdir(dir, 0755); ATF_REQUIRE(fs::is_directory(dir)); } ATF_TEST_CASE_WITH_CLEANUP(is_directory__fail); ATF_TEST_CASE_HEAD(is_directory__fail) { set_md_var("require.user", "unprivileged"); } ATF_TEST_CASE_BODY(is_directory__fail) { fs::mkdir(fs::path("dir"), 0000); ATF_REQUIRE_THROW(fs::error, fs::is_directory(fs::path("dir/foo"))); } ATF_TEST_CASE_CLEANUP(is_directory__fail) { if (::chmod("dir", 0755) == -1) { // If we cannot restore the original permissions, we cannot do much // more. However, leaving an unwritable directory behind will cause the // runtime engine to report us as broken. } } ATF_TEST_CASE_WITHOUT_HEAD(mkdir__ok); ATF_TEST_CASE_BODY(mkdir__ok) { fs::mkdir(fs::path("dir"), 0755); ATF_REQUIRE(lookup(".", "dir", S_IFDIR)); } ATF_TEST_CASE_WITHOUT_HEAD(mkdir__enoent); ATF_TEST_CASE_BODY(mkdir__enoent) { try { fs::mkdir(fs::path("dir1/dir2"), 0755); fail("system_error not raised"); } catch (const fs::system_error& e) { ATF_REQUIRE_EQ(ENOENT, e.original_errno()); } ATF_REQUIRE(!lookup(".", "dir1", S_IFDIR)); ATF_REQUIRE(!lookup(".", "dir2", S_IFDIR)); } ATF_TEST_CASE_WITHOUT_HEAD(mkdir_p__one_component); ATF_TEST_CASE_BODY(mkdir_p__one_component) { ATF_REQUIRE(!lookup(".", "new-dir", S_IFDIR)); fs::mkdir_p(fs::path("new-dir"), 0755); ATF_REQUIRE(lookup(".", "new-dir", S_IFDIR)); } ATF_TEST_CASE_WITHOUT_HEAD(mkdir_p__many_components); ATF_TEST_CASE_BODY(mkdir_p__many_components) { ATF_REQUIRE(!lookup(".", "a", S_IFDIR)); fs::mkdir_p(fs::path("a/b/c"), 0755); ATF_REQUIRE(lookup(".", "a", S_IFDIR)); ATF_REQUIRE(lookup("a", "b", S_IFDIR)); ATF_REQUIRE(lookup("a/b", "c", S_IFDIR)); } ATF_TEST_CASE_WITHOUT_HEAD(mkdir_p__already_exists); ATF_TEST_CASE_BODY(mkdir_p__already_exists) { fs::mkdir(fs::path("a"), 0755); fs::mkdir(fs::path("a/b"), 0755); fs::mkdir_p(fs::path("a/b"), 0755); } ATF_TEST_CASE(mkdir_p__eacces) ATF_TEST_CASE_HEAD(mkdir_p__eacces) { set_md_var("require.user", "unprivileged"); } ATF_TEST_CASE_BODY(mkdir_p__eacces) { fs::mkdir(fs::path("a"), 0755); fs::mkdir(fs::path("a/b"), 0755); ATF_REQUIRE(::chmod("a/b", 0555) != -1); try { fs::mkdir_p(fs::path("a/b/c/d"), 0755); fail("system_error not raised"); } catch (const fs::system_error& e) { ATF_REQUIRE_EQ(EACCES, e.original_errno()); } ATF_REQUIRE(lookup(".", "a", S_IFDIR)); ATF_REQUIRE(lookup("a", "b", S_IFDIR)); ATF_REQUIRE(!lookup(".", "c", S_IFDIR)); ATF_REQUIRE(!lookup("a", "c", S_IFDIR)); ATF_REQUIRE(!lookup("a/b", "c", S_IFDIR)); } ATF_TEST_CASE_WITHOUT_HEAD(mkdtemp_public) ATF_TEST_CASE_BODY(mkdtemp_public) { const fs::path tmpdir = fs::current_path() / "tmp"; utils::setenv("TMPDIR", tmpdir.str()); fs::mkdir(tmpdir, 0755); const std::string dir_template("tempdir.XXXXXX"); const fs::path tempdir = fs::mkdtemp_public(dir_template); ATF_REQUIRE(!lookup("tmp", dir_template.c_str(), S_IFDIR)); ATF_REQUIRE(lookup("tmp", tempdir.leaf_name().c_str(), S_IFDIR)); } ATF_TEST_CASE(mkdtemp_public__getcwd_as_non_root) ATF_TEST_CASE_HEAD(mkdtemp_public__getcwd_as_non_root) { set_md_var("require.config", "unprivileged-user"); set_md_var("require.user", "root"); } ATF_TEST_CASE_BODY(mkdtemp_public__getcwd_as_non_root) { const std::string dir_template("dir.XXXXXX"); const fs::path dir = fs::mkdtemp_public(dir_template); const fs::path subdir = dir / "subdir"; fs::mkdir(subdir, 0755); const uid_t old_euid = ::geteuid(); const gid_t old_egid = ::getegid(); const passwd::user unprivileged_user = passwd::find_user_by_name( get_config_var("unprivileged-user")); ATF_REQUIRE(::setegid(unprivileged_user.gid) != -1); ATF_REQUIRE(::seteuid(unprivileged_user.uid) != -1); // The next code block runs as non-root. We cannot use any ATF macros nor // functions in it because a failure would cause the test to attempt to // write to the ATF result file which may not be writable as non-root. bool failed = false; { try { if (::chdir(subdir.c_str()) == -1) { std::cerr << "Cannot enter directory\n"; failed |= true; } else { fs::current_path(); } } catch (const fs::error& e) { failed |= true; std::cerr << "Failed to query current path in: " << subdir << '\n'; } if (::seteuid(old_euid) == -1) { std::cerr << "Failed to restore euid; cannot continue\n"; std::abort(); } if (::setegid(old_egid) == -1) { std::cerr << "Failed to restore egid; cannot continue\n"; std::abort(); } } if (failed) fail("Test failed; see stdout for details"); } ATF_TEST_CASE(mkdtemp_public__search_permissions_as_non_root) ATF_TEST_CASE_HEAD(mkdtemp_public__search_permissions_as_non_root) { set_md_var("require.config", "unprivileged-user"); set_md_var("require.user", "root"); } ATF_TEST_CASE_BODY(mkdtemp_public__search_permissions_as_non_root) { const std::string dir_template("dir.XXXXXX"); const fs::path dir = fs::mkdtemp_public(dir_template); const fs::path cookie = dir / "not-secret"; atf::utils::create_file(cookie.str(), "this is readable"); // We are running as root so there is no reason to assume that our current // work directory is accessible by non-root. Weaken the permissions so that // our code below works. ATF_REQUIRE(::chmod(".", 0755) != -1); const uid_t old_euid = ::geteuid(); const gid_t old_egid = ::getegid(); const passwd::user unprivileged_user = passwd::find_user_by_name( get_config_var("unprivileged-user")); ATF_REQUIRE(::setegid(unprivileged_user.gid) != -1); ATF_REQUIRE(::seteuid(unprivileged_user.uid) != -1); // The next code block runs as non-root. We cannot use any ATF macros nor // functions in it because a failure would cause the test to attempt to // write to the ATF result file which may not be writable as non-root. bool failed = false; { try { const std::string contents = utils::read_file(cookie); std::cerr << "Read contents: " << contents << '\n'; failed |= (contents != "this is readable"); } catch (const std::runtime_error& e) { failed |= true; std::cerr << "Failed to read " << cookie << '\n'; } if (::seteuid(old_euid) == -1) { std::cerr << "Failed to restore euid; cannot continue\n"; std::abort(); } if (::setegid(old_egid) == -1) { std::cerr << "Failed to restore egid; cannot continue\n"; std::abort(); } } if (failed) fail("Test failed; see stdout for details"); } ATF_TEST_CASE_WITHOUT_HEAD(mkstemp) ATF_TEST_CASE_BODY(mkstemp) { const fs::path tmpdir = fs::current_path() / "tmp"; utils::setenv("TMPDIR", tmpdir.str()); fs::mkdir(tmpdir, 0755); const std::string file_template("tempfile.XXXXXX"); const fs::path tempfile = fs::mkstemp(file_template); ATF_REQUIRE(!lookup("tmp", file_template.c_str(), S_IFREG)); ATF_REQUIRE(lookup("tmp", tempfile.leaf_name().c_str(), S_IFREG)); } static void test_mount_tmpfs_ok(const units::bytes& size) { const fs::path mount_point("mount_point"); fs::mkdir(mount_point, 0755); try { atf::utils::create_file("outside", ""); fs::mount_tmpfs(mount_point, size); atf::utils::create_file("mounted", ""); atf::utils::create_file((mount_point / "inside").str(), ""); struct ::stat outside, inside; ATF_REQUIRE(::stat("outside", &outside) != -1); ATF_REQUIRE(::stat((mount_point / "inside").c_str(), &inside) != -1); ATF_REQUIRE(outside.st_dev != inside.st_dev); fs::unmount(mount_point); } catch (const fs::unsupported_operation_error& e) { ATF_SKIP(e.what()); } } ATF_TEST_CASE_WITH_CLEANUP(mount_tmpfs__ok__default_size) ATF_TEST_CASE_HEAD(mount_tmpfs__ok__default_size) { set_md_var("require.user", "root"); } ATF_TEST_CASE_BODY(mount_tmpfs__ok__default_size) { test_mount_tmpfs_ok(units::bytes()); } ATF_TEST_CASE_CLEANUP(mount_tmpfs__ok__default_size) { cleanup_mount_point(fs::path("mounted"), fs::path("mount_point")); } ATF_TEST_CASE_WITH_CLEANUP(mount_tmpfs__ok__explicit_size) ATF_TEST_CASE_HEAD(mount_tmpfs__ok__explicit_size) { set_md_var("require.user", "root"); } ATF_TEST_CASE_BODY(mount_tmpfs__ok__explicit_size) { test_mount_tmpfs_ok(units::bytes(10 * units::MB)); } ATF_TEST_CASE_CLEANUP(mount_tmpfs__ok__explicit_size) { cleanup_mount_point(fs::path("mounted"), fs::path("mount_point")); } ATF_TEST_CASE(mount_tmpfs__fail) ATF_TEST_CASE_HEAD(mount_tmpfs__fail) { set_md_var("require.user", "root"); } ATF_TEST_CASE_BODY(mount_tmpfs__fail) { try { fs::mount_tmpfs(fs::path("non-existent")); } catch (const fs::unsupported_operation_error& e) { ATF_SKIP(e.what()); } catch (const fs::error& e) { // Expected. } } ATF_TEST_CASE_WITHOUT_HEAD(rm_r__empty); ATF_TEST_CASE_BODY(rm_r__empty) { fs::mkdir(fs::path("root"), 0755); ATF_REQUIRE(lookup(".", "root", S_IFDIR)); fs::rm_r(fs::path("root")); ATF_REQUIRE(!lookup(".", "root", S_IFDIR)); } ATF_TEST_CASE_WITHOUT_HEAD(rm_r__files_and_directories); ATF_TEST_CASE_BODY(rm_r__files_and_directories) { fs::mkdir(fs::path("root"), 0755); atf::utils::create_file("root/.hidden_file", ""); fs::mkdir(fs::path("root/.hidden_dir"), 0755); atf::utils::create_file("root/.hidden_dir/a", ""); atf::utils::create_file("root/file", ""); atf::utils::create_file("root/with spaces", ""); fs::mkdir(fs::path("root/dir1"), 0755); fs::mkdir(fs::path("root/dir1/dir2"), 0755); atf::utils::create_file("root/dir1/dir2/file", ""); fs::mkdir(fs::path("root/dir1/dir3"), 0755); ATF_REQUIRE(lookup(".", "root", S_IFDIR)); fs::rm_r(fs::path("root")); ATF_REQUIRE(!lookup(".", "root", S_IFDIR)); } +ATF_TEST_CASE_WITHOUT_HEAD(rm_r__bad_perms); +ATF_TEST_CASE_BODY(rm_r__bad_perms) +{ + fs::mkdir(fs::path("root"), 0755); + fs::mkdir(fs::path("root/dir"), 0755); + atf::utils::create_file("root/dir/file", ""); + ::chmod(fs::path("root/dir").c_str(), 0000); + ATF_REQUIRE(lookup(".", "root", S_IFDIR)); + fs::rm_r(fs::path("root")); + ATF_REQUIRE(!lookup(".", "root", S_IFDIR)); +} + + ATF_TEST_CASE_WITHOUT_HEAD(rmdir__ok) ATF_TEST_CASE_BODY(rmdir__ok) { ATF_REQUIRE(::mkdir("foo", 0755) != -1); ATF_REQUIRE(::access("foo", X_OK) == 0); fs::rmdir(fs::path("foo")); ATF_REQUIRE(::access("foo", X_OK) == -1); } ATF_TEST_CASE_WITHOUT_HEAD(rmdir__fail) ATF_TEST_CASE_BODY(rmdir__fail) { ATF_REQUIRE_THROW_RE(fs::system_error, "Removal of foo failed", fs::rmdir(fs::path("foo"))); } ATF_TEST_CASE_WITHOUT_HEAD(scan_directory__ok) ATF_TEST_CASE_BODY(scan_directory__ok) { fs::mkdir(fs::path("dir"), 0755); atf::utils::create_file("dir/foo", ""); atf::utils::create_file("dir/.hidden", ""); const std::set< fs::directory_entry > contents = fs::scan_directory( fs::path("dir")); std::set< fs::directory_entry > exp_contents; exp_contents.insert(fs::directory_entry(".")); exp_contents.insert(fs::directory_entry("..")); exp_contents.insert(fs::directory_entry(".hidden")); exp_contents.insert(fs::directory_entry("foo")); ATF_REQUIRE_EQ(exp_contents, contents); } ATF_TEST_CASE_WITHOUT_HEAD(scan_directory__fail) ATF_TEST_CASE_BODY(scan_directory__fail) { ATF_REQUIRE_THROW_RE(fs::system_error, "opendir(.*missing.*) failed", fs::scan_directory(fs::path("missing"))); } ATF_TEST_CASE_WITHOUT_HEAD(unlink__ok) ATF_TEST_CASE_BODY(unlink__ok) { atf::utils::create_file("foo", ""); ATF_REQUIRE(::access("foo", R_OK) == 0); fs::unlink(fs::path("foo")); ATF_REQUIRE(::access("foo", R_OK) == -1); } ATF_TEST_CASE_WITHOUT_HEAD(unlink__fail) ATF_TEST_CASE_BODY(unlink__fail) { ATF_REQUIRE_THROW_RE(fs::system_error, "Removal of foo failed", fs::unlink(fs::path("foo"))); } ATF_TEST_CASE(unmount__ok) ATF_TEST_CASE_HEAD(unmount__ok) { set_md_var("require.user", "root"); } ATF_TEST_CASE_BODY(unmount__ok) { const fs::path mount_point("mount_point"); fs::mkdir(mount_point, 0755); atf::utils::create_file((mount_point / "test1").str(), ""); try { fs::mount_tmpfs(mount_point); } catch (const fs::unsupported_operation_error& e) { ATF_SKIP(e.what()); } atf::utils::create_file((mount_point / "test2").str(), ""); ATF_REQUIRE(!fs::exists(mount_point / "test1")); ATF_REQUIRE( fs::exists(mount_point / "test2")); fs::unmount(mount_point); ATF_REQUIRE( fs::exists(mount_point / "test1")); ATF_REQUIRE(!fs::exists(mount_point / "test2")); } ATF_TEST_CASE(unmount__fail) ATF_TEST_CASE_HEAD(unmount__fail) { set_md_var("require.user", "root"); } ATF_TEST_CASE_BODY(unmount__fail) { ATF_REQUIRE_THROW(fs::error, fs::unmount(fs::path("non-existent"))); } ATF_INIT_TEST_CASES(tcs) { ATF_ADD_TEST_CASE(tcs, copy__ok); ATF_ADD_TEST_CASE(tcs, copy__fail_open); ATF_ADD_TEST_CASE(tcs, copy__fail_create); ATF_ADD_TEST_CASE(tcs, current_path__ok); ATF_ADD_TEST_CASE(tcs, current_path__enoent); ATF_ADD_TEST_CASE(tcs, exists); ATF_ADD_TEST_CASE(tcs, find_in_path__no_path); ATF_ADD_TEST_CASE(tcs, find_in_path__empty_path); ATF_ADD_TEST_CASE(tcs, find_in_path__one_component); ATF_ADD_TEST_CASE(tcs, find_in_path__many_components); ATF_ADD_TEST_CASE(tcs, find_in_path__current_directory); ATF_ADD_TEST_CASE(tcs, find_in_path__always_absolute); ATF_ADD_TEST_CASE(tcs, free_disk_space__ok__smoke); ATF_ADD_TEST_CASE(tcs, free_disk_space__ok__real); ATF_ADD_TEST_CASE(tcs, free_disk_space__fail); ATF_ADD_TEST_CASE(tcs, is_directory__ok); ATF_ADD_TEST_CASE(tcs, is_directory__fail); ATF_ADD_TEST_CASE(tcs, mkdir__ok); ATF_ADD_TEST_CASE(tcs, mkdir__enoent); ATF_ADD_TEST_CASE(tcs, mkdir_p__one_component); ATF_ADD_TEST_CASE(tcs, mkdir_p__many_components); ATF_ADD_TEST_CASE(tcs, mkdir_p__already_exists); ATF_ADD_TEST_CASE(tcs, mkdir_p__eacces); ATF_ADD_TEST_CASE(tcs, mkdtemp_public); ATF_ADD_TEST_CASE(tcs, mkdtemp_public__getcwd_as_non_root); ATF_ADD_TEST_CASE(tcs, mkdtemp_public__search_permissions_as_non_root); ATF_ADD_TEST_CASE(tcs, mkstemp); ATF_ADD_TEST_CASE(tcs, mount_tmpfs__ok__default_size); ATF_ADD_TEST_CASE(tcs, mount_tmpfs__ok__explicit_size); ATF_ADD_TEST_CASE(tcs, mount_tmpfs__fail); ATF_ADD_TEST_CASE(tcs, rm_r__empty); ATF_ADD_TEST_CASE(tcs, rm_r__files_and_directories); + ATF_ADD_TEST_CASE(tcs, rm_r__bad_perms); ATF_ADD_TEST_CASE(tcs, rmdir__ok); ATF_ADD_TEST_CASE(tcs, rmdir__fail); ATF_ADD_TEST_CASE(tcs, scan_directory__ok); ATF_ADD_TEST_CASE(tcs, scan_directory__fail); ATF_ADD_TEST_CASE(tcs, unlink__ok); ATF_ADD_TEST_CASE(tcs, unlink__fail); ATF_ADD_TEST_CASE(tcs, unmount__ok); ATF_ADD_TEST_CASE(tcs, unmount__fail); }