From f788f67c23648be208317ba6a4b902e09359925d Mon Sep 17 00:00:00 2001 From: Henry Daitx Date: Thu, 17 Jan 2019 16:11:20 +0000 Subject: [PATCH] Fix fastdeploy failure in Windows adb --fastdeploy creates a TemporaryFile to which the stdout for a shell command is redirected. This happens while the file is still open (the TemporaryFile object holds the file handle). In Linux this works, but Windows blocks the operation with an error of "The process cannot access the file because it is being used by another process". This change closes the file before the shell tries to write to it. Test: mm -j 72 Test: adb install --fastdeploy --force-agent --local-agent /mnt/raid/boat-attack-apk/boat-attack-swappy.apk Bug: 122592986 Change-Id: Iaaaf62cda43e4714d7f979e6a690549b383a7b82 --- adb/client/adb_install.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/adb/client/adb_install.cpp b/adb/client/adb_install.cpp index bd5508cfd..7a4a21bbb 100644 --- a/adb/client/adb_install.cpp +++ b/adb/client/adb_install.cpp @@ -33,7 +33,6 @@ #include "client/file_sync_client.h" #include "commandline.h" #include "fastdeploy.h" -#include "sysdeps.h" static constexpr int kFastDeployMinApi = 24; @@ -159,17 +158,23 @@ static int install_app_streamed(int argc, const char** argv, bool use_fastdeploy if (use_fastdeploy == true) { TemporaryFile metadataTmpFile; - TemporaryFile patchTmpFile; + std::string patchTmpFilePath; + { + TemporaryFile patchTmpFile; + patchTmpFile.DoNotRemove(); + patchTmpFilePath = patchTmpFile.path; + } FILE* metadataFile = fopen(metadataTmpFile.path, "wb"); extract_metadata(file, metadataFile); fclose(metadataFile); - create_patch(file, metadataTmpFile.path, patchTmpFile.path); + create_patch(file, metadataTmpFile.path, patchTmpFilePath.c_str()); // pass all but 1st (command) and last (apk path) parameters through to pm for // session creation std::vector pm_args{argv + 1, argv + argc - 1}; - install_patch(file, patchTmpFile.path, pm_args.size(), pm_args.data()); + install_patch(file, patchTmpFilePath.c_str(), pm_args.size(), pm_args.data()); + adb_unlink(patchTmpFilePath.c_str()); delete_device_patch_file(file); return 0; } else {