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

[RPM] Fix handling paths containing whitespaces #733

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions pkg/rpm/augment_rpm_files_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
import sys
import json

# NOTE: Keep this in sync with the same variable in rpm.bzl
# NOTE: Keep those two in sync with the same variables in rpm_pfg.bzl
_INSTALL_FILE_STANZA_FMT = """
install -d %{{buildroot}}/$(dirname {1})
cp {0} %{{buildroot}}/{1}
install -d "%{{buildroot}}/$(dirname '{1}')"
cp '{0}' '%{{buildroot}}/{1}'
""".strip()

_FILE_MODE_STANZA_FMT = """
{0} "{1}"
aiuto marked this conversation as resolved.
Show resolved Hide resolved
""".strip()

# Cheapo arg parsing. Currently this script is single-purpose.
Expand Down Expand Up @@ -69,9 +73,7 @@
os.path.join(root, f),
full_dest
))
dir_files_segments.append(
d["tags"] + " " + full_dest
)
dir_files_segments.append(_FILE_MODE_STANZA_FMT.format(d["tags"], full_dest))

with open(existing_install_script_path, 'r') as fh:
existing_install_script = fh.read()
Expand Down
29 changes: 17 additions & 12 deletions pkg/rpm_pfg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ spec_filetype = [".spec", ".spec.in", ".spec.tpl"]
#
# TODO(nacl, #292): cp -r does not do the right thing with TreeArtifacts
_INSTALL_FILE_STANZA_FMT = """
install -d %{{buildroot}}/$(dirname {1})
cp {0} %{{buildroot}}/{1}
"""
install -d "%{{buildroot}}/$(dirname '{1}')"
cp '{0}' '%{{buildroot}}/{1}'
""".strip()

# TODO(nacl): __install
# {0} is the directory name
#
# This may not be strictly necessary, given that they'll be created in the
# CPIO when rpmbuild processes the `%files` list.
_INSTALL_DIR_STANZA_FMT = """
install -d %{{buildroot}}/{0}
"""
install -d '%{{buildroot}}/{0}'
""".strip()

# {0} is the name of the link, {1} is the target, {2} is the desired symlink "mode".
#
Expand All @@ -74,12 +74,17 @@ install -d %{{buildroot}}/{0}
# XXX: This may not apply all that well to users of cygwin and mingw. We'll
# deal with that when the time comes.
_INSTALL_SYMLINK_STANZA_FMT = """
%{{__install}} -d %{{buildroot}}/$(dirname {0})
%{{__ln_s}} {1} %{{buildroot}}/{0}
%{{__install}} -d "%{{buildroot}}/$(dirname '{0}')"
%{{__ln_s}} '{1}' '%{{buildroot}}/{0}'
%if "%_host_os" != "linux"
%{{__chmod}} -h {2} %{{buildroot}}/{0}
%{{__chmod}} -h {2} '%{{buildroot}}/{0}'
%endif
"""
""".strip()

# {0} is the file tag, {1} is the the path to file
_FILE_MODE_STANZA_FMT = """
{0} "{1}"
""".strip()

def _package_contents_metadata(origin_label, grouping_label):
"""Named construct for helping to identify conflicting packaged contents"""
Expand Down Expand Up @@ -170,7 +175,7 @@ def _process_files(pfi, origin_label, grouping_label, file_base, dest_check_map,
})
else:
# Files are well-known. Take care of them right here.
rpm_files_list.append(file_base + " " + abs_dest)
rpm_files_list.append(_FILE_MODE_STANZA_FMT.format(file_base, abs_dest))
install_script_pieces.append(_INSTALL_FILE_STANZA_FMT.format(
src.path,
abs_dest,
Expand All @@ -185,7 +190,7 @@ def _process_dirs(pdi, origin_label, grouping_label, file_base, dest_check_map,
dest_check_map[dest] = metadata

abs_dirname = _make_absolute_if_not_already_or_is_macro(dest)
rpm_files_list.append(file_base + " " + abs_dirname)
rpm_files_list.append(_FILE_MODE_STANZA_FMT.format(file_base, abs_dirname))

install_script_pieces.append(_INSTALL_DIR_STANZA_FMT.format(
abs_dirname,
Expand All @@ -199,7 +204,7 @@ def _process_symlink(psi, origin_label, grouping_label, file_base, dest_check_ma
dest_check_map[psi.destination] = metadata

abs_dest = _make_absolute_if_not_already_or_is_macro(psi.destination)
rpm_files_list.append(file_base + " " + abs_dest)
rpm_files_list.append(_FILE_MODE_STANZA_FMT.format(file_base, abs_dest))
install_script_pieces.append(_INSTALL_SYMLINK_STANZA_FMT.format(
abs_dest,
psi.target,
Expand Down