diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/libply/ply-utils.c | 34 | ||||
| -rw-r--r-- | src/libply/ply-utils.h | 8 |
2 files changed, 28 insertions, 14 deletions
diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index f98f21a..0467b78 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -659,18 +659,26 @@ ply_create_directory (const char *directory) } 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) @@ -678,19 +686,25 @@ ply_create_scratch_directory (const char *directory) 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); + ply_restore_errno (); 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 diff --git a/src/libply/ply-utils.h b/src/libply/ply-utils.h index ff545dd..ec46fef 100644 --- a/src/libply/ply-utils.h +++ b/src/libply/ply-utils.h @@ -69,8 +69,6 @@ void ply_restore_errno (void); 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, @@ -78,8 +76,10 @@ 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 */ |
