aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bin/update.sh33
-rw-r--r--src/db.sh15
-rw-r--r--src/os.sh33
-rw-r--r--src/vars.sh2
4 files changed, 43 insertions, 40 deletions
diff --git a/bin/update.sh b/bin/update.sh
index c67fd26..6c9ab78 100644
--- a/bin/update.sh
+++ b/bin/update.sh
@@ -32,33 +32,11 @@ src_dir="$( cd -- "$script_dir/../src" && pwd )"
readonly src_dir
. "$src_dir/common.sh"
+. "$src_dir/os.sh"
. "$src_dir/path.sh"
. "$src_dir/vars.sh"
. "$src_dir/db.sh"
-# Cygwin-related stuff
-
-os="$( uname -o )"
-readonly os
-
-is_cygwin() {
- test "$os" == 'Cygwin'
-}
-
-check_symlinks_enabled_cygwin() {
- case "${CYGWIN-}" in
- *winsymlinks:native*) ;;
- *winsymlinks:nativestrict*) ;;
-
- *)
- dump "native Windows symlinks aren't enabled in Cygwin" >&2
- return 1
- ;;
- esac
-}
-
-# Main routines
-
script_usage() {
local msg
for msg; do
@@ -118,18 +96,9 @@ parse_script_options() {
done
}
-check_symlinks_enabled() {
- if is_cygwin; then
- check_symlinks_enabled_cygwin
- else
- return 0
- fi
-}
-
main() {
parse_script_options "$@"
check_symlinks_enabled
- ensure_database_exists
read_database
unlink_obsolete_entries
link_all_entries
diff --git a/src/db.sh b/src/db.sh
index 2d67edb..ab1f82f 100644
--- a/src/db.sh
+++ b/src/db.sh
@@ -45,10 +45,6 @@ update_database_path() {
mkdir -p -- "$db_dir"
}
-ensure_database_exists() {
- [ -f "$db_path" ] || is_dry_run || > "$db_path"
-}
-
add_entry() {
local entry
for entry; do
@@ -63,8 +59,12 @@ add_entry() {
symlink_var_dir="$( resolve_variable "$var_name" )"
local subpath="${entry#%$var_name%/}"
- local shared_path="$shared_var_dir/$subpath"
- local symlink_path="$symlink_var_dir/$subpath"
+ local shared_path="$shared_var_dir"
+ [ "$shared_var_dir" != / ] && shared_path="$shared_path/"
+ shared_path="$shared_path$subpath"
+ local symlink_path="$symlink_var_dir"
+ [ "$symlink_var_dir" != / ] && symlink_path="$symlink_path/"
+ symlink_path="$symlink_path$subpath"
dump " shared file path: $shared_path"
dump " symlink path: $symlink_path"
@@ -85,7 +85,7 @@ remove_entry() {
}
read_database() {
- [ ! -f "$db_path" ] && is_dry_run && return 0
+ [ ! -r "$db_path" ] && return 0
local entry
while IFS= read -d '' -r entry; do
@@ -229,6 +229,7 @@ unlink_all_entries() {
if symlink_points_to_shared_file "$entry"; then
dump ' ... removing the symlink'
is_dry_run || unlink_entry "$entry"
+ remove_entry "$entry"
else
dump " ... not a symlink or doesn't point to the shared file"
remove_entry "$entry"
diff --git a/src/os.sh b/src/os.sh
new file mode 100644
index 0000000..2a532cd
--- /dev/null
+++ b/src/os.sh
@@ -0,0 +1,33 @@
+# Copyright (c) 2016 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "Configuration file sharing" project.
+# For details, see https://github.com/egor-tensin/config-links.
+# Distributed under the MIT License.
+
+# Mostly Cygwin-related stuff
+
+os="$( uname -o )"
+readonly os
+
+is_cygwin() {
+ test "$os" == 'Cygwin'
+}
+
+check_symlinks_enabled_cygwin() {
+ case "${CYGWIN-}" in
+ *winsymlinks:native*) ;;
+ *winsymlinks:nativestrict*) ;;
+
+ *)
+ dump "native Windows symlinks aren't enabled in Cygwin" >&2
+ return 1
+ ;;
+ esac
+}
+
+check_symlinks_enabled() {
+ if is_cygwin; then
+ check_symlinks_enabled_cygwin
+ else
+ return 0
+ fi
+}
diff --git a/src/vars.sh b/src/vars.sh
index d74506b..2bac2ff 100644
--- a/src/vars.sh
+++ b/src/vars.sh
@@ -21,7 +21,7 @@ resolve_variable() {
fi
if [ "$var_name" = "$root_var_name" ]; then
- echo ''
+ echo '/'
return 0
fi