From 8ec2c5828d00cd9670e9a232480aa20371cf8ee7 Mon Sep 17 00:00:00 2001 From: Christopher Fujino Date: Fri, 30 Aug 2019 14:13:36 -0700 Subject: [PATCH] fix recursiveCopy to preserve executable bit (#39505) --- dev/devicelab/lib/framework/utils.dart | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/dev/devicelab/lib/framework/utils.dart b/dev/devicelab/lib/framework/utils.dart index a18602891ad..e5f3d34b85d 100644 --- a/dev/devicelab/lib/framework/utils.dart +++ b/dev/devicelab/lib/framework/utils.dart @@ -124,6 +124,11 @@ void recursiveCopy(Directory source, Directory target) { else if (entity is File) { final File dest = File(path.join(target.path, name)); dest.writeAsBytesSync(entity.readAsBytesSync()); + // Preserve executable bit + final String modes = entity.statSync().modeString(); + if (modes != null && modes.contains('x')) { + makeExecutable(dest); + } } } } @@ -134,6 +139,27 @@ FileSystemEntity move(FileSystemEntity whatToMove, .renameSync(path.join(to.path, name ?? path.basename(whatToMove.path))); } +/// Equivalent of `chmod a+x file` +void makeExecutable(File file) { + // Windows files do not have an executable bit + if (Platform.isWindows) { + return; + } + final ProcessResult result = _processManager.runSync([ + 'chmod', + 'a+x', + file.path, + ]); + + if (result.exitCode != 0) { + throw FileSystemException( + 'Error making ${file.path} executable.\n' + '${result.stderr}', + file.path, + ); + } +} + /// Equivalent of `mkdir directory`. void mkdir(Directory directory) { directory.createSync();