Skip to content

Commit d542434

Browse files
niheavenAsh258
andcommitted
opt(core): Get rid of 'fullpath'
Co-Authored-By: Jakub Čábera <cabera.jakub@gmail.com>
1 parent b71b507 commit d542434

10 files changed

Lines changed: 22 additions & 24 deletions

File tree

bin/checkhashes.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ foreach ($current in $MANIFESTS) {
115115

116116
dl_with_cache $current.app $version $_ $null $null -use_cache:$UseCache
117117

118-
$to_check = fullpath (cache_path $current.app $version $_)
118+
$to_check = cache_path $current.app $version $_
119119
$actual_hash = compute_hash $to_check $algorithm
120120

121121
# Append type of algorithm to both expected and actual if it's not sha256
@@ -140,7 +140,7 @@ foreach ($current in $MANIFESTS) {
140140
Write-Host "$($current.app): " -NoNewline
141141
Write-Host 'Mismatch found ' -ForegroundColor Red
142142
$mismatched | ForEach-Object {
143-
$file = fullpath (cache_path $current.app $version $current.urls[$_])
143+
$file = cache_path $current.app $version $current.urls[$_]
144144
Write-Host "`tURL:`t`t$($current.urls[$_])"
145145
if (Test-Path $file) {
146146
Write-Host "`tFirst bytes:`t$((get_magic_bytes_pretty $file ' ').ToUpper())"

lib/autoupdate.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ function get_hash_for_app([String] $app, $config, [String] $version, [String] $u
274274
write-host -f darkred "URL $url is not valid"
275275
return $null
276276
}
277-
$file = fullpath (cache_path $app $version $url)
277+
$file = cache_path $app $version $url
278278
$hash = compute_hash $file 'sha256'
279279
write-host -f DarkYellow 'Computed hash: ' -NoNewline
280280
write-host -f Green $hash

lib/core.ps1

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,12 @@ function url_remote_filename($url) {
352352
}
353353

354354
function ensure($dir) { if(!(test-path $dir)) { mkdir $dir > $null }; resolve-path $dir }
355-
function fullpath($path) { # should be ~ rooted
356-
$executionContext.sessionState.path.getUnresolvedProviderPathFromPSPath($path)
355+
function Get-AbsolutePath {
356+
param (
357+
[String]
358+
$Path
359+
) # should be ~ rooted
360+
return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path)
357361
}
358362
function relpath($path) { "$($myinvocation.psscriptroot)\$path" } # relative to calling script
359363
function friendly_path($path) {
@@ -615,7 +619,6 @@ function search_in_path($target) {
615619

616620
function ensure_in_path($dir, $global) {
617621
$path = env 'PATH' $global
618-
$dir = fullpath $dir
619622
if($path -notmatch [regex]::escape($dir)) {
620623
write-output "Adding $(friendly_path $dir) to $(if($global){'global'}else{'your'}) path."
621624

@@ -678,8 +681,6 @@ function strip_path($orig_path, $dir) {
678681
}
679682

680683
function remove_from_path($dir,$global) {
681-
$dir = fullpath $dir
682-
683684
# future sessions
684685
$was_in_path, $newpath = strip_path (env 'path' $global) $dir
685686
if($was_in_path) {
@@ -936,16 +937,19 @@ Optimize-SecurityProtocol
936937

937938
# Scoop root directory
938939
$scoopdir = $env:SCOOP, (get_config 'rootPath'), "$env:USERPROFILE\scoop" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
940+
$scoopdir = Get-AbsolutePath -Path $scoopdir
939941

940942
# Scoop global apps directory
941943
$globaldir = $env:SCOOP_GLOBAL, (get_config 'globalPath'), "$env:ProgramData\scoop" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -first 1
944+
$globaldir = Get-AbsolutePath -Path $globaldir
942945

943946
# Scoop cache directory
944947
# Note: Setting the SCOOP_CACHE environment variable to use a shared directory
945948
# is experimental and untested. There may be concurrency issues when
946949
# multiple users write and access cached files at the same time.
947950
# Use at your own risk.
948951
$cachedir = $env:SCOOP_CACHE, (get_config 'cachePath'), "$scoopdir\cache" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -first 1
952+
$cachedir = Get-AbsolutePath -Path $cachedir
949953

950954
# Scoop config file migration
951955
$configHome = $env:XDG_CONFIG_HOME, "$env:USERPROFILE\.config" | Select-Object -First 1

lib/install.ps1

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function Find-Manifest($app, $bucket) {
104104
}
105105

106106
function dl_with_cache($app, $version, $url, $to, $cookies = $null, $use_cache = $true) {
107-
$cached = fullpath (cache_path $app $version $url)
107+
$cached = cache_path $app $version $url
108108

109109
if(!(test-path $cached) -or !$use_cache) {
110110
ensure $cachedir | Out-Null
@@ -254,7 +254,7 @@ function dl_with_cache_aria2($app, $version, $manifest, $architecture, $dir, $co
254254
'filename' = url_filename $url
255255
'target' = "$dir\$(url_filename $url)"
256256
'cachename' = fname (cache_path $app $version $url)
257-
'source' = fullpath (cache_path $app $version $url)
257+
'source' = cache_path $app $version $url
258258
}
259259

260260
if(!(test-path $data.$url.source)) {
@@ -575,8 +575,6 @@ function cookie_header($cookies) {
575575
}
576576

577577
function is_in_dir($dir, $check) {
578-
$check = "$(fullpath $check)"
579-
$dir = "$(fullpath $dir)"
580578
$check -match "^$([regex]::escape("$dir"))(\\|`$)"
581579
}
582580

@@ -602,7 +600,6 @@ function hash_for_url($manifest, $url, $arch) {
602600

603601
# returns (ok, err)
604602
function check_hash($file, $hash, $app_name) {
605-
$file = fullpath $file
606603
if(!$hash) {
607604
warn "Warning: No hash in manifest. SHA256 for '$(fname $file)' is:`n $(compute_hash $file 'sha256')"
608605
return $true, $null
@@ -942,7 +939,6 @@ function env_add_path($manifest, $dir, $global) {
942939
}
943940

944941
function add_first_in_path($dir, $global) {
945-
$dir = fullpath $dir
946942

947943
# future sessions
948944
$null, $currpath = strip_path (env 'path' $global) $dir
@@ -1097,8 +1093,8 @@ function persist_data($manifest, $original_dir, $persist_dir) {
10971093

10981094
$source = $source.TrimEnd("/").TrimEnd("\\")
10991095

1100-
$source = fullpath "$dir\$source"
1101-
$target = fullpath "$persist_dir\$target"
1096+
$source = "$dir\$source"
1097+
$target = "$persist_dir\$target"
11021098

11031099
# if we have had persist data in the store, just create link and go
11041100
if (Test-Path $target) {

lib/manifest.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
. "$psscriptroot/autoupdate.ps1"
33

44
function manifest_path($app, $bucket) {
5-
fullpath "$(Find-BucketDirectory $bucket)\$(sanitary_path $app).json"
5+
return "$(Find-BucketDirectory $bucket)\$(sanitary_path $app).json"
66
}
77

88
function parse_json($path) {

lib/psmodules.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ function ensure_in_psmodulepath($dir, $global) {
4949
if(!$global -and $null -eq $path) {
5050
$path = "$env:USERPROFILE\Documents\WindowsPowerShell\Modules"
5151
}
52-
$dir = fullpath $dir
5352
if($path -notmatch [regex]::escape($dir)) {
5453
write-output "Adding $(friendly_path $dir) to $(if($global){'global'}else{'your'}) PowerShell module path."
5554

libexec/scoop-status.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
reset_aliases
1212

1313
# check if scoop needs updating
14-
$currentdir = fullpath $(versiondir 'scoop' 'current')
14+
$currentdir = versiondir 'scoop' 'current'
1515
$needs_update = $false
1616

1717
if(test-path "$currentdir\.git") {

libexec/scoop-update.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ function update_scoop() {
7373
if ($null -eq $last_update) {$last_update = [System.DateTime]::Now}
7474
$last_update = $last_update.ToString('s')
7575
$show_update_log = get_config 'show_update_log' $true
76-
$currentdir = fullpath $(versiondir 'scoop' 'current')
76+
$currentdir = versiondir 'scoop' 'current'
7777
if (!(test-path "$currentdir\.git")) {
78-
$newdir = fullpath $(versiondir 'scoop' 'new')
78+
$newdir = versiondir 'scoop' 'new'
7979

8080
# get git scoop
8181
git_clone -q $configRepo --branch $configBranch --single-branch "`"$newdir`""
@@ -214,7 +214,7 @@ function update($app, $global, $quiet = $false, $independent, $suggested, $use_c
214214

215215
if ($check_hash) {
216216
$manifest_hash = hash_for_url $manifest $url $architecture
217-
$source = fullpath (cache_path $app $version $url)
217+
$source = cache_path $app $version $url
218218
$ok, $err = check_hash $source $manifest_hash $(show_app $app $bucket)
219219

220220
if (!$ok) {

libexec/scoop-which.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ try {
1717

1818
$path = "$($gcm.path)"
1919
$usershims = "$(resolve-path $(shimdir $false))"
20-
$globalshims = fullpath (shimdir $true) # don't resolve: may not exist
20+
$globalshims = shimdir $true
2121

2222
if($path.endswith(".ps1") -and ($path -like "$usershims*" -or $path -like "$globalshims*")) {
2323
$shimtext = Get-Content $path

test/Scoop-Install.Tests.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ describe "is_in_dir" -Tag 'Scoop' {
7070
is_in_dir "C:\test" "C:\foo" | should -BeFalse
7171
is_in_dir "C:\test" "C:\test\foo\baz.zip" | should -betrue
7272

73-
is_in_dir "test" "$psscriptroot" | should -betrue
7473
is_in_dir "$psscriptroot\..\" "$psscriptroot" | should -BeFalse
7574
}
7675
}

0 commit comments

Comments
 (0)