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

Method RemovePermissions

Sources/Shared/IO/FileSystem.cpp:2704–2736  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected