| 2702 | } |
| 2703 | |
| 2704 | bool FileSystem::RemovePermissions(StringView path, Permission mode) |
| 2705 | { |
| 2706 | if (path.empty()) return false; |
| 2707 | |
| 2708 | #if defined(DEATH_TARGET_WINDOWS) |
| 2709 | SmallVector<wchar_t, MAX_PATH + 1> pathW(path.size() + 1); |
| 2710 | Utf8::ToUtf16(pathW.data(), std::int32_t(pathW.size()), path.data(), std::int32_t(path.size())); |
| 2711 | DWORD attrs = ::GetFileAttributesW(pathW.data()); |
| 2712 | if (attrs != INVALID_FILE_ATTRIBUTES) { |
| 2713 | // Removing the write permission |
| 2714 | if ((mode & Permission::Write) == Permission::Write && (attrs & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY) { |
| 2715 | attrs |= FILE_ATTRIBUTE_READONLY; |
| 2716 | return ::SetFileAttributesW(pathW.data(), attrs); |
| 2717 | } |
| 2718 | return true; |
| 2719 | } |
| 2720 | return false; |
| 2721 | #else |
| 2722 | auto nullTerminatedPath = String::nullTerminatedView(path); |
| 2723 | # if defined(DEATH_TARGET_ANDROID) |
| 2724 | if (AndroidAssetStream::TryGetAssetPath(nullTerminatedPath)) { |
| 2725 | return false; |
| 2726 | } |
| 2727 | # endif |
| 2728 | struct stat sb; |
| 2729 | if (::stat(nullTerminatedPath.data(), &sb) != 0) { |
| 2730 | return false; |
| 2731 | } |
| 2732 | const std::uint32_t currentMode = sb.st_mode; |
| 2733 | const std::uint32_t newMode = RemovePermissionsFromCurrent(currentMode, mode); |
| 2734 | return (::chmod(nullTerminatedPath.data(), newMode) == 0); |
| 2735 | #endif |
| 2736 | } |
| 2737 | |
| 2738 | bool FileSystem::LaunchDirectoryAsync(StringView path) |
| 2739 | { |