Fixing a bug creating bundles with nested dirs

When creating bundles, users get to choose if they want to include
files, directories, links or dangling links in the bundle. Whatever
choice they make, all the directories that are part of the path of
the element should be created. This wasn't happening when creating
bundles with nested directories, for example /foo/bar/baz, in this
case only dir /foo/bar/baz was being added to the manifest of the
bundle but neither /foo nor /foo/bar were being added.

This commit fixes that issue. It also adds a safety feature where
it adds a '/' in front of dirs or file when user creates a bundle
in case they forget to add it themselves so the function works
properly even in that situation. For example with something like
this "-f /foo,bar/baz"
This commit is contained in:
Castulo Martinez
2018-08-20 15:11:19 -07:00
committed by Matthew Johnson
parent 25f6589ae6
commit 82fc78075b
+36 -17
View File
@@ -802,7 +802,32 @@ create_bundle() {
EOM
}
add_dirs() {
if [[ "$val" != "/"* ]]; then
val=/"$val"
fi
# if the directories the file is don't exist, add them to the bundle,
# do not add all the directories of the tracking file /usr/share/clear/bundles,
# this file is added in every bundle by default, it would add too much overhead
# for most tests
fdir=$(dirname "${val%:*}")
if [ ! "$(sudo cat "$manifest" | grep -x "D\\.\\.\\..*$fdir")" ] && [ "$fdir" != "/usr/share/clear/bundles" ] \
&& [ "$fdir" != "/" ]; then
bundle_dir=$(create_dir "$files_path")
add_to_manifest "$manifest" "$bundle_dir" "$fdir"
# add each one of the directories of the path if they are not in the manifest already
while [ "$(dirname "$fdir")" != "/" ]; do
fdir=$(dirname "$fdir")
if [ ! "$(sudo cat "$manifest" | grep -x "D\\.\\.\\..*$fdir")" ]; then
add_to_manifest "$manifest" "$bundle_dir" "$fdir"
fi
done
fi
}
local OPTIND
local opt
local dir_list
@@ -875,8 +900,8 @@ create_bundle() {
# Create a zero pack for the bundle and add the directory to it
sudo tar -cf "$version_path"/pack-"$bundle_name"-from-0.tar --exclude="$bundle_dir"/* "$bundle_dir"
for val in "${dir_list[@]}"; do
# the "/" directory is not allowed in the manifest
if [ val != "/" ]; then
add_dirs
if [ "$val" != "/" ]; then
add_to_manifest "$manifest" "$bundle_dir" "$val"
if [ "$local_bundle" = true ]; then
sudo mkdir -p "$target_path$val"
@@ -886,20 +911,7 @@ create_bundle() {
# 3) Create the requested file(s)
for val in "${file_list[@]}"; do
# if the directories the file is don't exist, add them to the bundle
# there are 2 exceptions, the dir of the tracking file and "\"
fdir=$(dirname "$val")
if [ ! "$(sudo cat "$manifest" | grep -x "D\\.\\.\\..*$fdir")" ] && [ "$fdir" != "/usr/share/clear/bundles" ] && [ "$fdir" != "/" ]; then
bundle_dir=$(create_dir "$files_path")
add_to_manifest "$manifest" "$bundle_dir" "$fdir"
# add each one of the directories of the path if they are not in the manifest already
while [ "$(dirname "$fdir")" != "/" ]; do
fdir=$(dirname "$fdir")
if [ ! "$(sudo cat "$manifest" | grep -x "D\\.\\.\\..*$fdir")" ]; then
add_to_manifest "$manifest" "$bundle_dir" "$fdir"
fi
done
fi
add_dirs
bundle_file=$(create_file "$files_path")
if [ "$DEBUG" == true ]; then
echo "file -> $bundle_file"
@@ -917,6 +929,9 @@ create_bundle() {
# 4) Create the requested link(s) in the bundle
for val in "${link_list[@]}"; do
if [[ "$val" != "/"* ]]; then
val=/"$val"
fi
# if the directory the link is doesn't exist,
# add it to the bundle (except if the directory is "/")
fdir=$(dirname "$val")
@@ -948,6 +963,9 @@ create_bundle() {
# 5) Create the requested dangling link(s) in the bundle
for val in "${dangling_link_list[@]}"; do
if [[ "$val" != "/"* ]]; then
val=/"$val"
fi
# if the directory the link is doesn't exist,
# add it to the bundle (except if the directory is "/")
fdir=$(dirname "$val")
@@ -981,6 +999,7 @@ create_bundle() {
create_tar "$version_path"/Manifest.MoM
# 8) Sign the manifest MoM
sudo rm -f "$version_path"/Manifest.MoM.sig
sign_manifest "$version_path"/Manifest.MoM
# 9) Create the subscription to the bundle if the local_bundle flag is enabled