[bugfix] new-pass/edit-pass with nonexistence dir failed
This commit is contained in:
parent
2b62e0ffcd
commit
26afd4ab3b
|
@ -29,14 +29,15 @@ function GeneratePassword {
|
||||||
|
|
||||||
function EnsurePath {
|
function EnsurePath {
|
||||||
param(
|
param(
|
||||||
[String] $PassPath
|
[String] $OrigPassPath,
|
||||||
|
[Bool] $CreateParents=$false
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!$PassPath) {
|
if (!$OrigPassPath) {
|
||||||
throw "path is empty!"
|
throw "path is empty!"
|
||||||
}
|
}
|
||||||
|
|
||||||
$PassPath = Join-Path $PASSWORD_STORE_DIR $PassPath
|
$PassPath = Join-Path $PASSWORD_STORE_DIR $OrigPassPath
|
||||||
if (!$PassPath.EndsWith(".gpg")) {
|
if (!$PassPath.EndsWith(".gpg")) {
|
||||||
$PassPath = $PassPath + ".gpg"
|
$PassPath = $PassPath + ".gpg"
|
||||||
}
|
}
|
||||||
|
@ -44,8 +45,9 @@ function EnsurePath {
|
||||||
if (!$dir) {
|
if (!$dir) {
|
||||||
$dir = "."
|
$dir = "."
|
||||||
}
|
}
|
||||||
if (!(Test-Path -PathType Container $dir)) {
|
if ($CreateParents -and !(Test-Path -PathType Container $dir)) {
|
||||||
New-Item -ItemType Directory -Path $dir
|
# all output will be returned, suppress all output for all subcommands
|
||||||
|
New-Item -ItemType Directory -Path $dir > $null
|
||||||
}
|
}
|
||||||
return $PassPath
|
return $PassPath
|
||||||
}
|
}
|
||||||
|
@ -80,7 +82,7 @@ function Edit-Pass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$PassPath = EnsurePath $PassPath
|
$PassPath = EnsurePath -CreateParents $true $PassPath
|
||||||
|
|
||||||
$tmpfile = (New-TemporaryFile).FullName
|
$tmpfile = (New-TemporaryFile).FullName
|
||||||
gpg --decrypt $PassPath > $tmpfile
|
gpg --decrypt $PassPath > $tmpfile
|
||||||
|
@ -99,7 +101,7 @@ function New-Pass {
|
||||||
[Parameter(Mandatory=$true)] [String] $PassPath
|
[Parameter(Mandatory=$true)] [String] $PassPath
|
||||||
)
|
)
|
||||||
|
|
||||||
$PassPath = EnsurePath $PassPath
|
$PassPath = EnsurePath -CreateParents $true $PassPath
|
||||||
$pass = GeneratePassword
|
$pass = GeneratePassword
|
||||||
if (Test-Path -PathType Leaf $PassPath) {
|
if (Test-Path -PathType Leaf $PassPath) {
|
||||||
$text = gpg --decrypt $PassPath
|
$text = gpg --decrypt $PassPath
|
||||||
|
|
Loading…
Reference in New Issue
Block a user