}
bool
-ply_create_scratch_directory (const char *directory)
+ply_create_detachable_directory (const char *directory)
{
- int dir_fd;
+
assert (directory != NULL);
assert (directory[0] != '\0');
if (!ply_create_directory (directory))
return false;
- if (mount ("none", directory, "ramfs", 0, NULL) < 0)
+ if (mount ("none", directory, "tmpfs", 0, NULL) < 0)
return false;
+ return true;
+}
+
+int
+ply_detach_directory (const char *directory)
+{
+ int dir_fd;
+
dir_fd = open (directory, O_RDONLY);
if (dir_fd < 0)
+ {
+ ply_save_errno ();
+ umount (directory);
+ ply_restore_errno ();
+ return dir_fd;
+ }
+
+ if (umount2 (directory, PLY_SUPER_SECRET_LAZY_UNMOUNT_FLAG) < 0)
{
ply_save_errno ();
umount (directory);
return false;
}
- umount2 (directory, PLY_SUPER_SECRET_LAZY_UNMOUNT_FLAG);
+ rmdir (directory);
- /* contents of directory will remain visible to process
- * (and children) until the file descriptor is closed.
- *
- * We're leaking the file descriptor below, so it will
- * remain around until the process exits
+ /* return a file descriptor to the directory because it's now been
+ * detached from the filesystem. The user can fchdir to this
+ * directory and work from it that way
*/
- return true;
+ return dir_fd;
}
static bool
bool ply_directory_exists (const char *dir);
bool ply_file_exists (const char *file);
-bool ply_file_system_is_mounted (const char *type,
- const char *path);
ply_module_handle_t *ply_open_module (const char *module_path);
ply_module_function_t ply_module_look_up_function (ply_module_handle_t *handle,
void ply_close_module (ply_module_handle_t *handle);
bool ply_create_directory (const char *directory);
-bool ply_create_scratch_directory (const char *directory);
-
+bool ply_create_detachable_directory (const char *directory);
+int ply_detach_directory (const char *directory);
+bool ply_copy_file (const char *source, const char *destination);
+bool ply_copy_directory (const char *source, const char *destination);
#endif
#endif /* PLY_UTILS_H */