sadanand48 commented on code in PR #8477:
URL: https://github.com/apache/ozone/pull/8477#discussion_r2158219491


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/Archiver.java:
##########
@@ -111,6 +114,34 @@ public static long includeFile(File file, String entryName,
     return bytes;
   }
 
+  /**
+   * Creates a hardlink for the given file in a temporary directory, adds it
+   * as an entry in the archive, and includes its contents in the archive 
output.
+   * The temporary hardlink is deleted after processing.
+   */
+  public static long linkAndIncludeFile(File file, String entryName,
+      ArchiveOutputStream<TarArchiveEntry> archiveOutput, Path tmpDir) throws 
IOException {
+    File link = tmpDir.resolve(entryName).toFile();
+    long bytes = 0;
+    try {
+      Files.createLink(link.toPath(), file.toPath());
+      TarArchiveEntry entry = archiveOutput.createArchiveEntry(link, 
entryName);
+      archiveOutput.putArchiveEntry(entry);
+      try (InputStream input = Files.newInputStream(link.toPath())) {
+        bytes = IOUtils.copyLarge(input, archiveOutput);
+      }
+      archiveOutput.closeArchiveEntry();
+    } catch (IOException ioe) {
+      LOG.error("Couldn't create hardlink for file {} while including it in 
tarball.",

Review Comment:
   done. threw the exception here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to