-
Notifications
You must be signed in to change notification settings - Fork 217
pkg_tar: package_dir_file is not applied to pkg_mkdirs entries #758
Description
When a directory is created using pkg_mkdirs, it seems that pkg_tar does not apply the prefix to it.
Application of the prefix happens through normalize_path:
rules_pkg/pkg/private/tar/build_tar.py
Lines 65 to 75 in ff60b34
| def normalize_path(self, path: str) -> str: | |
| dest = normpath(path) | |
| # paths should not have a leading ./ | |
| if dest.startswith('./'): | |
| dest = dest[2:] | |
| # No path should ever come in with slashs on either end, but protect | |
| # against that anyway. | |
| dest = dest.strip('/') | |
| if self.directory: | |
| dest = self.directory + dest | |
| return dest |
at least for files
rules_pkg/pkg/private/tar/build_tar.py
Line 89 in ff60b34
| dest = self.normalize_path(destfile) |
and symlinks
rules_pkg/pkg/private/tar/build_tar.py
Line 178 in ff60b34
| dest = self.normalize_path(symlink) |
as well as for tree artifacts (though without using reusing the function)
rules_pkg/pkg/private/tar/build_tar.py
Lines 229 to 236 in ff60b34
| dest = destpath.strip('/') # redundant, dests should never have / here | |
| if self.directory and self.directory != '/': | |
| dest = self.directory.lstrip('/') + '/' + dest | |
| # Again, we expect /-style paths. | |
| dest = normpath(dest) | |
| # normpath may be ".", and dest paths should not start with "./" | |
| dest = '' if dest == '.' else dest + '/' |
however it doesn't happen for empty files
rules_pkg/pkg/private/tar/build_tar.py
Lines 106 to 139 in ff60b34
| def add_empty_file(self, | |
| destfile, | |
| mode=None, | |
| ids=None, | |
| names=None, | |
| kind=tarfile.REGTYPE): | |
| """Add a file to the tar file. | |
| Args: | |
| destfile: the name of the file in the layer | |
| mode: force to set the specified mode, defaults to 644 | |
| ids: (uid, gid) for the file to set ownership | |
| names: (username, groupname) for the file to set ownership. | |
| kind: type of the file. tarfile.DIRTYPE for directory. An empty file | |
| will be created as `destfile` in the layer. | |
| """ | |
| dest = destfile.lstrip('/') # Remove leading slashes | |
| # If mode is unspecified, assume read only | |
| if mode is None: | |
| mode = 0o644 | |
| if ids is None: | |
| ids = (0, 0) | |
| if names is None: | |
| names = ('', '') | |
| dest = normpath(dest) | |
| self.tarfile.add_file( | |
| dest, | |
| content='' if kind == tarfile.REGTYPE else None, | |
| kind=kind, | |
| mode=mode, | |
| uid=ids[0], | |
| gid=ids[1], | |
| uname=names[0], | |
| gname=names[1]) |
or directories
rules_pkg/pkg/private/tar/build_tar.py
Lines 141 to 152 in ff60b34
| def add_empty_dir(self, destpath, mode=None, ids=None, names=None): | |
| """Add a directory to the tar file. | |
| Args: | |
| destpath: the name of the directory in the layer | |
| mode: force to set the specified mode, defaults to 644 | |
| ids: (uid, gid) for the file to set ownership | |
| names: (username, groupname) for the file to set ownership. An empty | |
| file will be created as `destfile` in the layer. | |
| """ | |
| self.add_empty_file( | |
| destpath, mode=mode, ids=ids, names=names, kind=tarfile.DIRTYPE) |
While I can imagine that there might be someone out there who wants to be able to impose a prefix on the files and symlinks in their tarball without also applying it to empty files or directories, that behavior is certainly surprising, and moreover if one needs to put an empty file or directory in a location with the prefix, and you're prefix depends on a file input (as in package_dir_file), you are out of luck.