| 2593 | } |
| 2594 | |
| 2595 | FileSystem::Permission FileSystem::GetPermissions(StringView path) |
| 2596 | { |
| 2597 | if (path.empty()) return Permission::None; |
| 2598 | |
| 2599 | #if defined(DEATH_TARGET_WINDOWS) |
| 2600 | SmallVector<wchar_t, MAX_PATH + 1> pathW(path.size() + 1); |
| 2601 | Utf8::ToUtf16(pathW.data(), std::int32_t(pathW.size()), path.data(), std::int32_t(path.size())); |
| 2602 | Permission mode = Permission::Read; |
| 2603 | if (IsExecutable(path)) { |
| 2604 | mode |= Permission::Execute; |
| 2605 | } |
| 2606 | const DWORD attrs = ::GetFileAttributesW(pathW.data()); |
| 2607 | if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_READONLY) == 0) { |
| 2608 | mode |= Permission::Write; |
| 2609 | } |
| 2610 | return mode; |
| 2611 | #else |
| 2612 | auto nullTerminatedPath = String::nullTerminatedView(path); |
| 2613 | # if defined(DEATH_TARGET_ANDROID) |
| 2614 | if (auto strippedPath = AndroidAssetStream::TryGetAssetPath(nullTerminatedPath)) { |
| 2615 | if (AndroidAssetStream::TryOpenDirectory(strippedPath)) { |
| 2616 | return Permission::Read | Permission::Execute; |
| 2617 | } else if (AndroidAssetStream::TryOpenFile(strippedPath)) { |
| 2618 | return Permission::Read; |
| 2619 | } else { |
| 2620 | return Permission::None; |
| 2621 | } |
| 2622 | } |
| 2623 | # endif |
| 2624 | struct stat sb; |
| 2625 | if (::stat(nullTerminatedPath.data(), &sb) != 0) { |
| 2626 | return Permission::None; |
| 2627 | } |
| 2628 | return NativeModeToEnum(sb.st_mode); |
| 2629 | #endif |
| 2630 | } |
| 2631 | |
| 2632 | bool FileSystem::ChangePermissions(StringView path, Permission mode) |
| 2633 | { |