Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 695160462
  • Loading branch information
DeviceInfra authored and copybara-github committed Nov 22, 2024
1 parent 2822b76 commit 571a208
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public enum BasicErrorId implements ErrorId {
LOCAL_FILE_CREATE_HARD_LINK_ERROR(30_125, ErrorType.UNDETERMINED),
LOCAL_FILE_UNZIP_FILENAME_NOT_MATCHED(30_126, ErrorType.CUSTOMER_ISSUE),
LOCAL_FILE_NEW_BUFFERED_WRITER_ERROR(30_127, ErrorType.UNDETERMINED),
LOCAL_FILE_TAR_EXTRACT_ERROR(30_128, ErrorType.UNDETERMINED),

LOCAL_DIR_IS_FILE(30_201, ErrorType.UNDETERMINED),
LOCAL_DIR_CREATE_ERROR(30_202, ErrorType.UNDETERMINED),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,27 @@ public long writeToFile(String filePath, InputStream input) throws MobileHarness
}
}

/** Extracts the tar.gz file to the target dir. */
public void extractTarGz(Path tarGzPath, Path targetDirPath)
throws MobileHarnessException, InterruptedException {
extractTarGz(tarGzPath.toString(), targetDirPath.toString());
}

/** Extracts the tar.gz file to the target dir. */
public void extractTarGz(String tarGzPath, String targetDirPath)
throws MobileHarnessException, InterruptedException {
try {
Command command =
Command.of(String.format("tar -zxvf %s -C %s", tarGzPath, targetDirPath).split(" "));
cmdExecutor.exec(command);
} catch (CommandException e) {
throw new MobileHarnessException(
BasicErrorId.LOCAL_FILE_TAR_EXTRACT_ERROR,
String.format("Failed to extract file %s to directory %s", tarGzPath, targetDirPath),
e);
}
}

/**
* Unzips the file to the target dir. If the target dir does not exist, will create it.
*
Expand Down

0 comments on commit 571a208

Please sign in to comment.