From f1c378c027db012956d5e8a9585004250550d581 Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Tue, 27 Jun 2017 05:33:18 -0400 Subject: Added functions for downloading/patching archives i.e., source tarballs are (partially) supported --- libs/common | 18 ++++++++++++++++++ libs/project | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) (limited to 'libs') diff --git a/libs/common b/libs/common index d0fd1203..c5c89483 100755 --- a/libs/common +++ b/libs/common @@ -64,6 +64,24 @@ arguments_list() { done } +download_wrapper() { + local download_dir="$1" + shift + local uris=($@) + + # TODO: Add support for curl, in addition + # to wget, for compatibility reasons + wget_options=( + --config=/dev/null + --secure-protocol=PFS + --directory-prefix="${download_dir}" + --continue + -- + ) + + wget "${wget_options[@]}" "${uris[@]}" +} + diff_patch_file() { local repository_path="$1" local patch_file_path="$2" diff --git a/libs/project b/libs/project index 38e9b40d..93f07ae5 100755 --- a/libs/project +++ b/libs/project @@ -504,6 +504,27 @@ project_sources_archive_missing_check() { fi } +project_sources_prepare() { + local project="$1" + local sources_path="$2" + + # Not implemented yet / May end up not being needed + #project_sources_prepare_blobs + project_sources_prepare_patch "${project}" "${sources_path}" "$@" +} + +project_sources_prepare_patch() { + local project="$1" + local sources_path="$2" + + local project_path="$(project_path "${project}")" + local patches_path="${project_path}/${PATCHES}" + + for patch in "${patches_path}"/[!.]*.{patch,diff}; do + diff_patch_file "${sources_path}" "${patch}" + done +} + project_blobs_path() { local project=$1 shift @@ -676,6 +697,45 @@ project_download_check_git() { git_project_prepare_check "$project" "$repository" "$@" } +project_download_archive() { + local project="$1" + shift + local archive_uri="$1" + shift + local archive_dsig_uri="$1" + + local archive="${archive_uri##*/}" + local compress_fmt="${archive##*.tar}" + + local directory_prefix="${root}/${SOURCES}" + local archive_path="${root}/${SOURCES}/${archive}" + local sources_path="${root}/${SOURCES}/${project}" + + if [[ "${compress_fmt#*.}" != "${ARCHIVE#*.}" ]]; then + ARCHIVE="tar${compress_fmt}" + fi + + # TODO: Split this code block into separate functions + # Archive verification will be included at that point in time + if ! project_sources_directory_filled_check "${project}"; then + wget_wrapper "${directory_prefix}" "${archive_uri}" "${archive_dsig_uri}" + archive_extract "${archive_path}" "${directory_prefix}" + + mv "${archive_path%.tar*}" "${sources_path}" + fi + + # Patch the source, if necessary + project_sources_prepare "${project}" "${sources_path}" +} + +project_download_check_archive() { + local project="$1" + local sources_path="$2" + + # TODO: Write the following function + #project_sources_archive_extract_check "${project}" "${sources_path}" +} + project_extract() { local project=$1 shift -- cgit v1.2.3-70-g09d2 From 9a67491b91bfc476d8c1c30dc2932d1967fb6720 Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Tue, 27 Jun 2017 12:21:09 -0400 Subject: Fixed bug in diff_patch_file() filename parsing. --- libs/common | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'libs') diff --git a/libs/common b/libs/common index c5c89483..7898f115 100755 --- a/libs/common +++ b/libs/common @@ -86,12 +86,13 @@ diff_patch_file() { local repository_path="$1" local patch_file_path="$2" - local filename_in_diff="$(sed -rne 's/^-{3} {1}(.*)$/\1/p' <"${patch_file_path}")" + # TODO: Improve handling of filenames to avoid gotchas w/ \n, \t, etc. + local filename_in_diff="$(sed -rne 's/^-{3}\s+([^ \r\n]*).*/\1/p' "${patch_file_path}")" local source_file_path - if ! ( grep -E '^-{3}.*/' <"${patch_file_path}" >/dev/null 2>&1 ); then - source_file_path="${repository_path}/${filename_in_diff##\ }" + if ! ( grep -E '^-{3}.*/' "${patch_file_path}" >/dev/null 2>&1 ); then + source_file_path="${repository_path}/${filename_in_diff}" else source_file_path="${repository_path}/${filename_in_diff##*/}" fi -- cgit v1.2.3-70-g09d2