Unverified Commit 74ab1bfb authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Ensure that cache dirs and files have appropriate permissions (#24669)

Fixes https://github.com/flutter/flutter/issues/24413
parent e7a4e7c3
...@@ -27,9 +27,11 @@ if [ ! -f "$ENGINE_STAMP" ] || [ "$ENGINE_VERSION" != `cat "$ENGINE_STAMP"` ]; t ...@@ -27,9 +27,11 @@ if [ ! -f "$ENGINE_STAMP" ] || [ "$ENGINE_VERSION" != `cat "$ENGINE_STAMP"` ]; t
case "$(uname -s)" in case "$(uname -s)" in
Darwin) Darwin)
DART_ZIP_NAME="dart-sdk-darwin-x64.zip" DART_ZIP_NAME="dart-sdk-darwin-x64.zip"
IS_USER_EXECUTABLE="-perm +100"
;; ;;
Linux) Linux)
DART_ZIP_NAME="dart-sdk-linux-x64.zip" DART_ZIP_NAME="dart-sdk-linux-x64.zip"
IS_USER_EXECUTABLE="-perm /u+x"
;; ;;
*) *)
echo "Unknown operating system. Cannot install Dart SDK." echo "Unknown operating system. Cannot install Dart SDK."
...@@ -48,7 +50,7 @@ if [ ! -f "$ENGINE_STAMP" ] || [ "$ENGINE_VERSION" != `cat "$ENGINE_STAMP"` ]; t ...@@ -48,7 +50,7 @@ if [ ! -f "$ENGINE_STAMP" ] || [ "$ENGINE_VERSION" != `cat "$ENGINE_STAMP"` ]; t
# install the new sdk # install the new sdk
rm -rf -- "$DART_SDK_PATH" rm -rf -- "$DART_SDK_PATH"
mkdir -p -- "$DART_SDK_PATH" mkdir -m 755 -p -- "$DART_SDK_PATH"
DART_SDK_ZIP="$FLUTTER_ROOT/bin/cache/$DART_ZIP_NAME" DART_SDK_ZIP="$FLUTTER_ROOT/bin/cache/$DART_ZIP_NAME"
curl --continue-at - --location --output "$DART_SDK_ZIP" "$DART_SDK_URL" 2>&1 || { curl --continue-at - --location --output "$DART_SDK_ZIP" "$DART_SDK_URL" 2>&1 || {
...@@ -70,6 +72,8 @@ if [ ! -f "$ENGINE_STAMP" ] || [ "$ENGINE_VERSION" != `cat "$ENGINE_STAMP"` ]; t ...@@ -70,6 +72,8 @@ if [ ! -f "$ENGINE_STAMP" ] || [ "$ENGINE_VERSION" != `cat "$ENGINE_STAMP"` ]; t
exit 1 exit 1
} }
rm -f -- "$DART_SDK_ZIP" rm -f -- "$DART_SDK_ZIP"
find "$DART_SDK_PATH" -type d -exec chmod 755 {} \;
find "$DART_SDK_PATH" -type f $IS_USER_EXECUTABLE -exec chmod a+x,a+r {} \;
echo "$ENGINE_VERSION" > "$ENGINE_STAMP" echo "$ENGINE_VERSION" > "$ENGINE_STAMP"
# delete any temporary sdk path # delete any temporary sdk path
......
...@@ -25,7 +25,15 @@ abstract class OperatingSystemUtils { ...@@ -25,7 +25,15 @@ abstract class OperatingSystemUtils {
OperatingSystemUtils._private(); OperatingSystemUtils._private();
/// Make the given file executable. This may be a no-op on some platforms. /// Make the given file executable. This may be a no-op on some platforms.
ProcessResult makeExecutable(File file); void makeExecutable(File file);
/// Updates the specified file system [entity] to have the file mode
/// bits set to the value defined by [mode], which can be specified in octal
/// (e.g. `644`) or symbolically (e.g. `u+x`).
///
/// On operating systems that do not support file mode bits, this will be a
/// no-op.
void chmod(FileSystemEntity entity, String mode);
/// Return the path (with symlinks resolved) to the given executable, or null /// Return the path (with symlinks resolved) to the given executable, or null
/// if `which` was not able to locate the binary. /// if `which` was not able to locate the binary.
...@@ -78,8 +86,13 @@ class _PosixUtils extends OperatingSystemUtils { ...@@ -78,8 +86,13 @@ class _PosixUtils extends OperatingSystemUtils {
_PosixUtils() : super._private(); _PosixUtils() : super._private();
@override @override
ProcessResult makeExecutable(File file) { void makeExecutable(File file) {
return processManager.runSync(<String>['chmod', 'a+x', file.path]); chmod(file, 'a+x');
}
@override
void chmod(FileSystemEntity entity, String mode) {
processManager.runSync(<String>['chmod', mode, entity.path]);
} }
@override @override
...@@ -152,11 +165,11 @@ class _PosixUtils extends OperatingSystemUtils { ...@@ -152,11 +165,11 @@ class _PosixUtils extends OperatingSystemUtils {
class _WindowsUtils extends OperatingSystemUtils { class _WindowsUtils extends OperatingSystemUtils {
_WindowsUtils() : super._private(); _WindowsUtils() : super._private();
// This is a no-op.
@override @override
ProcessResult makeExecutable(File file) { void makeExecutable(File file) {}
return ProcessResult(0, 0, null, null);
} @override
void chmod(FileSystemEntity entity, String mode) {}
@override @override
List<File> _which(String execName, {bool all = false}) { List<File> _which(String execName, {bool all = false}) {
......
...@@ -145,8 +145,10 @@ class Cache { ...@@ -145,8 +145,10 @@ class Cache {
/// Return a directory in the cache dir. For `pkg`, this will return `bin/cache/pkg`. /// Return a directory in the cache dir. For `pkg`, this will return `bin/cache/pkg`.
Directory getCacheDir(String name) { Directory getCacheDir(String name) {
final Directory dir = fs.directory(fs.path.join(getRoot().path, name)); final Directory dir = fs.directory(fs.path.join(getRoot().path, name));
if (!dir.existsSync()) if (!dir.existsSync()) {
dir.createSync(recursive: true); dir.createSync(recursive: true);
os.chmod(dir, '755');
}
return dir; return dir;
} }
...@@ -194,8 +196,10 @@ class Cache { ...@@ -194,8 +196,10 @@ class Cache {
final Directory thirdPartyDir = getArtifactDirectory('third_party'); final Directory thirdPartyDir = getArtifactDirectory('third_party');
final Directory serviceDir = fs.directory(fs.path.join(thirdPartyDir.path, serviceName)); final Directory serviceDir = fs.directory(fs.path.join(thirdPartyDir.path, serviceName));
if (!serviceDir.existsSync()) if (!serviceDir.existsSync()) {
serviceDir.createSync(recursive: true); serviceDir.createSync(recursive: true);
os.chmod(serviceDir, '755');
}
final File cachedFile = fs.file(fs.path.join(serviceDir.path, url.pathSegments.last)); final File cachedFile = fs.file(fs.path.join(serviceDir.path, url.pathSegments.last));
if (!cachedFile.existsSync()) { if (!cachedFile.existsSync()) {
...@@ -552,13 +556,16 @@ class FlutterEngine extends CachedArtifact { ...@@ -552,13 +556,16 @@ class FlutterEngine extends CachedArtifact {
return result; return result;
} }
void _makeFilesExecutable(Directory dir) { void _makeFilesExecutable(Directory dir) {
for (FileSystemEntity entity in dir.listSync()) { os.chmod(dir, 'a+r,a+x');
for (FileSystemEntity entity in dir.listSync(recursive: true)) {
if (entity is File) { if (entity is File) {
final String name = fs.path.basename(entity.path); final FileStat stat = entity.statSync();
if (name == 'flutter_tester') final bool isUserExecutable = ((stat.mode >> 6) & 0x1) == 1;
os.makeExecutable(entity); if (entity.basename == 'flutter_tester' || isUserExecutable) {
// Make the file readable and executable by all users.
os.chmod(entity, 'a+r,a+x');
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment