-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Adds entries for all directories in layer tarball. #772
Conversation
@@ -44,6 +45,12 @@ | |||
throws IOException { | |||
List<TarArchiveEntry> tarArchiveEntries = new ArrayList<>(); | |||
|
|||
// Adds the extraction path itself. | |||
TarArchiveEntry extractionPathDirectoryEntry = | |||
new TarArchiveEntry(Paths.get(".").toFile(), layerEntry.getExtractionPath()); |
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.
Not sure how to do this better than just using the current directory .
. Otherwise, we would have to either have a directory to use, or duplicate a lot of the logic in TarArchiveEntry
's constructor.
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.
Maybe add a more explicit comment about this? (e.g. // Adds the extraction path itself; to do this, we can just add the current directory named as the extraction path
)
@@ -45,7 +45,8 @@ | |||
throws IOException { | |||
List<TarArchiveEntry> tarArchiveEntries = new ArrayList<>(); | |||
|
|||
// Adds the extraction path itself. | |||
// Adds the extraction path itself; to do this, are adding the current directory to act as the |
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.
to do this, we are adding
// Adds the extraction path itself; to do this, we are adding the current directory to act as | ||
// the file input (since all directories are treated the same in TarArchiveEntry). | ||
TarArchiveEntry extractionPathDirectoryEntry = | ||
new TarArchiveEntry(Paths.get(".").toFile(), layerEntry.getExtractionPath()); |
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.
Given #727 (comment), I guess the extraction path is like /app/classes
, this directory gets the readable permission, but /app
does not.
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.
Hmm, yea that might be it. Will try to think of a good way to add parent directories of the extraction too.
Will need to add parent directories too.
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.
Man it'd be nice if redhat didn't use ancient docker.
directoriesToAdd.add(parentDirectory.toString()); | ||
} | ||
} | ||
// We are using the current directory to act as the file input (since all directories are |
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'm not sure I understand this comment
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.
The TarArchiveEntry
constructor can use a directory and sets up defaults like normalizing the path, normalizing the end separator (adds /
if not present), and sets default permissions. It just needs to check file.isDirectory
, so any File
that is a directory will do.
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 think we could think about trying to find a better TarArchiveEntry
or implement our own...
Unfortunately, this still doesn't fix #727 (comment) :( |
@chanseokoh Yea, perhaps we need to just set default permissions for all files. |
This can be merged and I'll file a followup PR for adding all directories to have default directory mode. |
I thought this was to set the 755 permissions to the directories (which turned out to work only for /app, /app/classes, app/resources, app/lib, ... and not for directories nested in them). So, if you are going to have a PR that will make all directories to have the default directory mode, I think this PR is not necessary? Or, is this PR still necessary and fixing something? |
@chanseokoh That is true, I'll just modify this PR then. |
is this PR ready? |
This PR is in terms of what it does, but it still doesn't seem to fix #727 (comment) |
This fixes #523 (#523 (comment)) and can be merged. |
for (TarArchiveEntry tarArchiveEntry : tarArchiveEntries) { | ||
// Adds all directories along extraction paths to explicitly set permissions for those | ||
// directories. | ||
for (Path parentDirectory : getParentDirectories(Paths.get(tarArchiveEntry.getName()))) { |
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 wonder if this wouldn't be better in TarStreamBuilder. This approach also generates a lot of garbage since for only the first file per parent actually needs to walk the parents.
An alternative would be to first sort the file list, then walk the list and add directory elements all at once to the TarStreamBuilder, and then add the files.
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.
Hmm, that's a good point. I'll change this to add parents by iterating backwards along the path and adding the parents in a post-order manner. This way, the entries don't need to be sorted before the parent directories are added and each parent list is only walked fully once.
// are treated the same in TarArchiveEntry). | ||
private static final File DIRECTORY_FILE = Paths.get(".").toFile(); | ||
|
||
/** Decorates an object with a separate object for {@link #hashCode}. */ |
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'd appreciate detail as to why this class is required. Is Path#hashCode()
possibly inconsistent? (UnixPath#hashCode()
looks fine)
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.
This was to have TarArchiveEntry
be hashed by the entry name. I'll actually remove this since it is more confusing than it needs to be.
// are treated the same in TarArchiveEntry). | ||
private static final File DIRECTORY_FILE = Paths.get(".").toFile(); | ||
|
||
/** Holds a list of {@link TarArchiveEntry}s with unique extraction paths. */ |
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.
Add a note that: Additions are assumed to be files. Directory entries are added as required.
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.
Added a note, though the additions do not necessary need to be regular files.
List<LayerEntry> layerEntries = this.layerEntries.build(); | ||
for (LayerEntry layerEntry : layerEntries) { | ||
// Converts layerEntry to list of TarArchiveEntrys and adds to uniqueTarArchiveEntries. | ||
buildAsTarArchiveEntries(layerEntry).forEach(uniqueTarArchiveEntries::add); |
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.
Would it make sense to break into two parts? This is quite a complex statement.
private static final File DIRECTORY_FILE = Paths.get(".").toFile(); | ||
|
||
/** | ||
* Holds a list of {@link TarArchiveEntry}s with unique extraction paths. The list also consists |
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.
s/consists of/includes/
@@ -34,6 +38,48 @@ | |||
*/ | |||
public class ReproducibleLayerBuilder { | |||
|
|||
// Uses the current directory to act as the file input to TarArchiveEntry (since all directories | |||
// are treated the same in TarArchiveEntry). | |||
private static final File DIRECTORY_FILE = Paths.get(".").toFile(); |
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.
Move into UniqueTarArchiveEntries
? Make as a java doc and include a link to TarArchiveEntry constructor as a @seealso
?
👍 |
Fixes #523
Works towards #727
This makes sure that permissions for directories in the container filesystem will all be the default 755.