PeterAlfredLee commented on a change in pull request #97:
URL: https://github.com/apache/commons-compress/pull/97#discussion_r420526669



##########
File path: 
src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
##########
@@ -384,12 +430,49 @@ public TarArchiveEntry(final File file, final String 
fileName) {
         } else {
             this.mode = DEFAULT_FILE_MODE;
             this.linkFlag = LF_NORMAL;
-            this.size = file.length();
+            try {
+                this.size = Files.size(file);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
             this.name = normalizedName;
         }
 
-        this.modTime = file.lastModified() / MILLIS_PER_SECOND;
         this.userName = "";
+
+        Set<String> availableAttributeViews = 
file.getFileSystem().supportedFileAttributeViews();
+        if (availableAttributeViews.contains("posix")) {
+            try {
+                final PosixFileAttributes posixFileAttributes = 
Files.readAttributes(file, PosixFileAttributes.class);
+                setModTime(posixFileAttributes.lastModifiedTime());
+                this.userName = posixFileAttributes.owner().getName();
+                this.groupName = posixFileAttributes.group().getName();
+                if (availableAttributeViews.contains("unix")) {
+                    this.userId = ((Number) Files.getAttribute(file, 
"unix:uid")).longValue();
+                    this.groupId = ((Number) Files.getAttribute(file, 
"unix:gid")).longValue();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        } else if (availableAttributeViews.contains("dos")) {
+            try {
+                final DosFileAttributes dosFileAttributes = 
Files.readAttributes(file, DosFileAttributes.class);
+                setModTime(dosFileAttributes.lastModifiedTime());
+
+                this.userName = Files.getOwner(file).getName();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        } else {
+            try {
+                final BasicFileAttributes basicFileAttributes = 
Files.readAttributes(file, BasicFileAttributes.class);
+                setModTime(basicFileAttributes.lastModifiedTime());
+
+                this.userName = Files.getOwner(file).getName();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }

Review comment:
       Maybe extract the if...else if...else part to a new method?




----------------------------------------------------------------
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.

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


Reply via email to