FileSystem.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2023, Cameron Youell <cameronyouell@gmail.com>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Error.h>
  9. #include <AK/String.h>
  10. #include <AK/StringView.h>
  11. #include <LibCore/File.h>
  12. #include <sys/stat.h>
  13. namespace FileSystem {
  14. #define DEFAULT_PATH "/usr/local/sbin:/usr/local/bin:/usr/bin:/bin"
  15. #define DEFAULT_PATH_SV "/usr/local/sbin:/usr/local/bin:/usr/bin:/bin"sv
  16. ErrorOr<String> current_working_directory();
  17. ErrorOr<String> absolute_path(StringView path);
  18. ErrorOr<String> real_path(StringView path);
  19. bool exists(StringView path);
  20. bool exists(int fd);
  21. bool is_directory(StringView path);
  22. bool is_directory(int fd);
  23. bool is_device(StringView path);
  24. bool is_device(int fd);
  25. bool is_block_device(StringView path);
  26. bool is_block_device(int fd);
  27. bool is_char_device(StringView path);
  28. bool is_char_device(int fd);
  29. bool is_link(StringView path);
  30. bool is_link(int fd);
  31. enum class RecursionMode {
  32. Allowed,
  33. Disallowed
  34. };
  35. enum class LinkMode {
  36. Allowed,
  37. Disallowed
  38. };
  39. enum class AddDuplicateFileMarker {
  40. Yes,
  41. No,
  42. };
  43. enum class PreserveMode {
  44. Nothing = 0,
  45. Permissions = (1 << 0),
  46. Ownership = (1 << 1),
  47. Timestamps = (1 << 2),
  48. };
  49. AK_ENUM_BITWISE_OPERATORS(PreserveMode);
  50. ErrorOr<void> copy_file(StringView destination_path, StringView source_path, struct stat const& source_stat, Core::File& source, PreserveMode = PreserveMode::Nothing);
  51. ErrorOr<void> copy_directory(StringView destination_path, StringView source_path, struct stat const& source_stat, LinkMode = LinkMode::Disallowed, PreserveMode = PreserveMode::Nothing);
  52. ErrorOr<void> copy_file_or_directory(StringView destination_path, StringView source_path, RecursionMode = RecursionMode::Allowed, LinkMode = LinkMode::Disallowed, AddDuplicateFileMarker = AddDuplicateFileMarker::Yes, PreserveMode = PreserveMode::Nothing);
  53. ErrorOr<void> remove(StringView path, RecursionMode);
  54. ErrorOr<size_t> size(StringView path);
  55. bool can_delete_or_move(StringView path);
  56. ErrorOr<String> read_link(StringView link_path);
  57. ErrorOr<void> link_file(StringView destination_path, StringView source_path);
  58. bool looks_like_shared_library(StringView path);
  59. }