Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Private/Get-InstallPath.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function Get-InstallPath {

# returns OS specific path for module installation, it support only -Scope CurrentUser
if ($IsLinux -or $IsOSX) {

$defaultPath = if ($IsLinux -or $IsOSX) {
#"$HOME/.local/share/powershell/Modules"
# https://github.com/PowerShell/PowerShellGet/blob/d4dfebbbec4dfbe73392719a8a331541ed75d508/src/PowerShellGet/private/modulefile/PartOne.ps1#L71
Join-Path (Split-Path -Path ([System.Management.Automation.Platform]::SelectProductNameForDirectory('USER_MODULES')) -Parent) 'Modules'
Expand All @@ -18,4 +19,22 @@ function Get-InstallPath {
}
}

$ModulePaths = $Env:PSModulePath -split (';:'[[int]($IsLinux -or $IsMacOS)])
if ($defaultPath -in $ModulePaths) {
$defaultPath
} else {
# default path is not in findable by get-module, try to avoid it
$writablePath = ''
foreach ($P1 in $ModulePaths) {
if (([string]::IsNullOrEmpty($writablePath)) -and (Test-PathWritable $P1)) {
$writablePath = $P1
}
}
if ([string]::IsNullOrEmpty($writablePath)) {
# we found no writable paths, return default one
$defaultPath
} else {
$writablePath
}
}
}
21 changes: 21 additions & 0 deletions Private/Test-PathWritable.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function Test-PathWritable {
param (
[string]$Path
)
# returns true if given directory is writable, false otherwise
if (!(Test-Path $Path -PathType Container)) {
#throw "Path $Path is not a directory"
$false
}

$FileName = Join-Path $Path ([io.path]::GetRandomFileName())

try {
[io.file]::OpenWrite($FileName).close()
[io.file]::Delete($FileName)
$true
} catch {
$false
}

}
5 changes: 4 additions & 1 deletion Tests/module/InstallModuleFromGit.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$ModuleName = 'InstallModuleFromGit'
$here = Split-Path -Parent $MyInvocation.MyCommand.Path # Tests/Module folder
$root = (get-item $here).Parent.Parent.FullName # module root folder
Import-Module (Join-Path $root "$ModuleName.psm1") -Force
Import-Module (Join-Path $root "$ModuleName.psd1") -Force


#
Expand Down Expand Up @@ -67,6 +67,8 @@ Describe 'Proper Functions Declaration' -Tag 'Other' {

Describe 'Proper Documentation' -Tag 'Documentation' {

Push-Location $root

It 'Updates documentation and does git diff' {

# install PlatyPS
Expand All @@ -92,6 +94,7 @@ Describe 'Proper Documentation' -Tag 'Documentation' {
}
}

Pop-Location
}


Expand Down