mirror of
https://github.com/ScoopInstaller/Scoop.git
synced 2026-09-24 06:15:44 +00:00
intial persist implementation
This commit is contained in:
@@ -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, "[/\\?:*<>|]", "") }
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user