Skip to content
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

Merged
merged 22 commits into from
Aug 28, 2018

Conversation

coollog
Copy link
Contributor

@coollog coollog commented Aug 1, 2018

Fixes #523
Works towards #727

This makes sure that permissions for directories in the container filesystem will all be the default 755.

@coollog coollog added this to the v0.9.9 milestone Aug 1, 2018
@coollog coollog requested a review from a team August 1, 2018 21:13
@@ -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());
Copy link
Contributor Author

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.

Copy link
Contributor

@TadCordle TadCordle Aug 2, 2018

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
Copy link
Contributor

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

TadCordle
TadCordle previously approved these changes Aug 2, 2018
// 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());
Copy link
Member

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.

Copy link
Contributor Author

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.

@coollog coollog dismissed TadCordle’s stale review August 2, 2018 16:07

Will need to add parent directories too.

loosebazooka
loosebazooka previously approved these changes Aug 2, 2018
Copy link
Member

@loosebazooka loosebazooka left a 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
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@chanseokoh
Copy link
Member

Unfortunately, this still doesn't fix #727 (comment) :(

@coollog
Copy link
Contributor Author

coollog commented Aug 2, 2018

@chanseokoh Yea, perhaps we need to just set default permissions for all files.

@loosebazooka loosebazooka dismissed their stale review August 2, 2018 23:56

looks like fix failed

@coollog
Copy link
Contributor Author

coollog commented Aug 7, 2018

This can be merged and I'll file a followup PR for adding all directories to have default directory mode.

@chanseokoh
Copy link
Member

chanseokoh commented Aug 7, 2018

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?

@coollog
Copy link
Contributor Author

coollog commented Aug 7, 2018

@chanseokoh That is true, I'll just modify this PR then.

@coollog coollog changed the title Adds extraction path directory to layer tarball. Adds entries for all directories in layer tarball. Aug 8, 2018
@loosebazooka
Copy link
Member

is this PR ready?

@coollog
Copy link
Contributor Author

coollog commented Aug 13, 2018

This PR is in terms of what it does, but it still doesn't seem to fix #727 (comment)

@TadCordle TadCordle modified the milestones: v0.9.9, v0.9.10 Aug 20, 2018
@coollog
Copy link
Contributor Author

coollog commented Aug 27, 2018

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()))) {
Copy link
Member

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.

Copy link
Contributor Author

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}. */
Copy link
Member

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)

Copy link
Contributor Author

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. */
Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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
Copy link
Member

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();
Copy link
Member

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?

@briandealwis
Copy link
Member

👍

@coollog coollog merged commit 54e1e2b into master Aug 28, 2018
@coollog coollog deleted the add-extraction-path-to-tar branch August 28, 2018 14:00
coollog added a commit that referenced this pull request Aug 28, 2018
coollog added a commit that referenced this pull request Aug 28, 2018
@coollog coollog restored the add-extraction-path-to-tar branch August 28, 2018 14:47
@coollog coollog deleted the add-extraction-path-to-tar branch August 28, 2018 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants