-
Notifications
You must be signed in to change notification settings - Fork 49
Add fixedEntryModificationTime attribute to AbstractZipArchiver #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,11 @@ public abstract class AbstractZipArchiver | |
extends AbstractArchiver | ||
{ | ||
|
||
/** | ||
* The minimum value for MS-DOS time format: 01 Jan 1980 00:00:00 UTC | ||
**/ | ||
private static final Long MIN_MS_DOS_TIME = 315532800000L; | ||
|
||
private String comment; | ||
|
||
/** | ||
|
@@ -132,6 +137,12 @@ public abstract class AbstractZipArchiver | |
|
||
protected ZipArchiveOutputStream zipArchiveOutputStream; | ||
|
||
/** | ||
* Will always use the given modification time for zipEntries if set. | ||
* The given modification time will be rounded up to {@link AbstractZipArchiver#MIN_MS_DOS_TIME}. | ||
*/ | ||
private Long fixedEntryModificationTime; | ||
|
||
private static int getJavaVersion() | ||
{ | ||
String javaSpecVersion = System.getProperty( "java.specification.version" ); | ||
|
@@ -212,6 +223,14 @@ public boolean isFilesonly() | |
return doFilesonly; | ||
} | ||
|
||
public Long getFixedEntryModificationTime() { | ||
return fixedEntryModificationTime; | ||
} | ||
|
||
public void setFixedEntryModificationTime(Long fixedEntryModificationTime) { | ||
this.fixedEntryModificationTime = fixedEntryModificationTime; | ||
} | ||
|
||
@Override | ||
protected void execute() | ||
throws ArchiverException, IOException | ||
|
@@ -578,7 +597,12 @@ public InputStream get() | |
|
||
private void setTime( java.util.zip.ZipEntry zipEntry, long lastModified ) | ||
{ | ||
zipEntry.setTime( lastModified + ( isJava7OrLower ? 1999 : 0 ) ); | ||
|
||
if (fixedEntryModificationTime != null) { | ||
zipEntry.setTime(Math.max(MIN_MS_DOS_TIME, fixedEntryModificationTime)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lower values like 0L produce weird Dates when reading (seen something like 8. Nov 1979, which normally cannot be expressed by MS-DOS time). Not sure if we should do the round-up here. |
||
} else { | ||
zipEntry.setTime( lastModified + ( isJava7OrLower ? 1999 : 0 ) ); | ||
} | ||
|
||
/* Consider adding extended file stamp support..... | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really think this should be some kind of Date object, not a long. I am also contemplating if this setter should be on AbstractArchiver, others could just throw UnsupportedOepratiionException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually wouldn't it be even better if it works the same way as forced file/dir modes? I mean they are logically related - forced file/dir modes are options to override the file permissions. This is option to override the last modified date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summarizing:
setModificationTime(Date modificationTime)
(+getter) onArchiver
private Date forcedModificationTime = null
onAbstractArchiver
modificationTime
field inArchiveEntry
)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me like ArchiveEntry needs modifcationTime with that is overridden much the same way as the "mode" field. As for per-entry modifiers I suggest you only add the ones you need for the patch. So please do like @plamentotev suggests