MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / AddPermissions

Method AddPermissions

Sources/Shared/IO/FileSystem.cpp:2670–2702  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2668 }
2669
2670 bool FileSystem::AddPermissions(StringView path, Permission mode)
2671 {
2672 if (path.empty()) return false;
2673
2674#if defined(DEATH_TARGET_WINDOWS)
2675 SmallVector<wchar_t, MAX_PATH + 1> pathW(path.size() + 1);
2676 Utf8::ToUtf16(pathW.data(), std::int32_t(pathW.size()), path.data(), std::int32_t(path.size()));
2677 DWORD attrs = ::GetFileAttributesW(pathW.data());
2678 if (attrs != INVALID_FILE_ATTRIBUTES) {
2679 // Adding the write permission
2680 if ((mode & Permission::Write) == Permission::Write && (attrs & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY) {
2681 attrs &= ~FILE_ATTRIBUTE_READONLY;
2682 return ::SetFileAttributesW(pathW.data(), attrs);
2683 }
2684 return true;
2685 }
2686 return false;
2687#else
2688 auto nullTerminatedPath = String::nullTerminatedView(path);
2689# if defined(DEATH_TARGET_ANDROID)
2690 if (AndroidAssetStream::TryGetAssetPath(nullTerminatedPath)) {
2691 return false;
2692 }
2693# endif
2694 struct stat sb;
2695 if (::stat(nullTerminatedPath.data(), &sb) != 0) {
2696 return false;
2697 }
2698 const std::uint32_t currentMode = sb.st_mode;
2699 const std::uint32_t newMode = AddPermissionsToCurrent(currentMode, mode);
2700 return (::chmod(nullTerminatedPath.data(), newMode) == 0);
2701#endif
2702 }
2703
2704 bool FileSystem::RemovePermissions(StringView path, Permission mode)
2705 {

Callers

nothing calls this directly

Calls 6

AddPermissionsToCurrentFunction · 0.85
statClass · 0.70
ToUtf16Function · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected