aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/db.sh15
-rw-r--r--src/os.sh33
-rw-r--r--src/vars.sh2
3 files changed, 42 insertions, 8 deletions
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