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

Support restoring workspace archives from another OS #1923

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 20 additions & 1 deletion lib/travis/build/script/shared/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,26 @@ def fetch
end

def expand
sh.cmd "tar -xPzf ${CASHER_DIR}/#{name}-fetch.tgz"
archive = "${CASHER_DIR}/#{name}-fetch.tgz"
# For any root directories that `tar` would be extracting stuff to,
# create missing ones and give the user permissions for existing ones.
# Needed when restoring an archive from another OS with a different filesystem hierarchy.
sh.raw "tar -tPf \"#{archive}\" | " +
# BSD(OSX) xargs doesn't support `-d` so -0 is the only way to handle paths with spaces.
# BSD awk doesn't support \0 in variables so have to use printf.
# BSD dirname doesn't support multiple arguments; -P 2 reduces time from 30s to 20s on a
# sample archive with ~20k entries, further increase doesn't reduce time.
"awk '{printf(\"%s%c\",$0,0)}' | " +
"xargs -0 $([[ $TRAVIS_OS_NAME =~ (osx|freebsd) ]] && echo '-n 1 -P 2') dirname | " +
"sort | uniq | " +
# Print only lines that don't have the same prefix as a previous one -- to get only root dirs.
# Initial `a` must be an impossible prefix. Since BSD awk doesn't support \0,
# \n is acceptable since `tar -t` delimits entries with \n with no option to change that
"awk 'index($0,a)!=1{a=$0;printf(\"%s%c\",$0,0)} BEGIN{a=\"\\n\"}' | " +
# `install` is more convenient than `mkdir -p` since it can set UID/GID as the same time.
# It only sets UID/GID on the leaf entry
"xargs -0 echo $([[ $TRAVIS_OS_NAME != 'windows' ]] && echo 'sudo') install -o \"${USER}\" -g \"$(id -g)\" -d"
sh.cmd "tar -xPf #{archive}"
end

# for creating workspace
Expand Down