intial persist implementation

This commit is contained in:
Rémy
2017-03-25 16:28:05 +01:00
parent 3c320f2a5c
commit cafefdf658
2 changed files with 41 additions and 0 deletions
+2
View File
@@ -56,8 +56,10 @@ function filesize($length) {
function basedir($global) { if($global) { return $globaldir } $scoopdir }
function appsdir($global) { "$(basedir $global)\apps" }
function shimdir($global) { "$(basedir $global)\shims" }
function datadir($app, $global) { "$(basedir $global)\data" }
function appdir($app, $global) { "$(appsdir $global)\$app" }
function versiondir($app, $version, $global) { "$(appdir $app $global)\$version" }
function appdatadir($app, $global) { "$(datadir $global)\$app" }
# apps
function sanitary_path($path) { return [regex]::replace($path, "[/\\?:*<>|]", "") }
+39
View File
@@ -31,6 +31,8 @@ function install_app($app, $architecture, $global, $suggested) {
echo "Installing '$app' ($version)."
$dir = ensure (versiondir $app $version $global)
$original_dir = $dir # keep reference to real (not linked) directory
$data_dir = ensure (appdatadir $app)
$fname = dl_urls $app $version $manifest $architecture $dir $use_cache $check_hash
unpack_inno $fname $manifest $dir
@@ -44,6 +46,10 @@ function install_app($app, $architecture, $global, $suggested) {
if($global) { ensure_scoop_in_path $global } # can assume local scoop is in path
env_add_path $manifest $dir $global
env_set $manifest $dir $global
# persist data
persist_data $manifest
# env_ensure_home $manifest $global (see comment for env_ensure_home)
post_install $manifest $architecture
@@ -941,6 +947,39 @@ function show_suggestions($suggested) {
}
}
# Persistent data
function persist_data($manifest) {
$persist = $manifest.persist
if($persist) {
if ($persist -is [String]) {
$persist = @($persist);
}
write-host "Persisting data..."
$persist | % {
# TODO implement [from, to]
$source_name = $_
$target_name = fname($_)
Write-Host -ForegroundColor Red $source_name $target_name
$source = "$original_dir\$source_name"
$target = "$data_dir\$target_name"
if (!(test-path $target)) {
# If we do not have data in the store we move the original
movedir $source $target # TODO check if file work too
} else {
# move original (keep a copy)
movedir $source "$source.original"
}
# create link
# TODO use /h for files
cmd /c "mklink /j $source $target" | out-null
}
}
}
# travelling directories have their contents moved from
# $from to $to when the app is updated.
# any files or directories that already exist in $to are skipped