-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows: mount path with leading slash is found in the project directory #12470
Comments
one point regarding handling from (my) users perspective. |
See #6967 |
consider the strange windows behavior with having drive letters and No idea about
so your second test case should fail on windows
willing to assist , if there's something (not GO) that would help and more special stuff
|
source="c:" or source ="d:" may be problematic cause they refer to the current folder of that drive. So if you are somewhere in c:... and address d: it may point to some unexpected unwanted folder. btw. docs state it must me forward slashes, but "c:\content" works fine |
@irkode you have some valid points. My take on this would be that if os.Stat("/foo/bar.txt") // Using the correct OS path separator ... throws an error (typically I'm not sure exactly happens in this particular case, but I'm pretty sure it can be explained re. the above. |
I played around a little with Windows style pathes and have a finding short resultGo's I'm new to Go, so there might be methods that handle that Dunno if this will affect Hugo code I could not identify issues if absolute paths are used (p.s. backslash and slash are handled properly) TL;TR;wrote a small Go program that
run that for several filenames and compared with the output of Windows Powershell tests
The Good answer for all tested combinations where
have an absolute path with the same drive the results are identical Even for Drive relative if the drive letter differs
Go's method seem not to handle Drive Relative paths respect the current working of the tested Drive drive C:
failing testcasesthis reads as:
CODEquite hacky powershell and my first Go program - please be generous. Go (mystat.go)package main
import (
"fmt"
"os"
"path/filepath"
)
func main() {
if len(os.Args) != 2 {
var arg0 = os.Args[0]
prg, _ := os.Stat(arg0)
fmt.Printf("Usage: %s <PATH>", prg.Name())
os.Exit(1)
}
var filename = os.Args[1]
_, err := os.Stat(filename)
if err != nil {
os.Exit(2)
} else {
absPath, err := filepath.Abs(filename)
if err != nil {
os.Exit(3)
} else {
fmt.Print(absPath)
os.Exit(0)
}
}
os.Exit(1)
} Powershell $mystat = "C:\mydir\winosstat\mystat.exe"
# This will be the current workin directories for finding files from
$driveCwds = @(
"c:\" # bar.txt
"c:\stat" # bar.txt & baz.txt
"c:\mydir" # neither
"c:\_repos" # neither
)
# Matrix test prefixes + pathes
$prefixes = @(
"",
"/",
"c:",
"c:/"
)
$pathes = @(
"bar.md"
"baz.md"
"stat/bar.md"
"stat/baz.md"
)
# Save Current Working directory to be able to go back after changing work director on other drive
$cwd = Get-Location
$driveCwds | % {
$driveCwd = $_
# Switch the tested drives working folder and come back
$newLoc = Set-location $driveCwd -PassThru
if ($cwd.Drive -ne $newLoc.Drive) {
Set-Location $cwd
}
$prefixes | % {
$pre = $_; $pathes | % {
$checkPath = $pre + $_
$winAbs = $Null
$goAbs = $Null
# check Windows style
$winStat = Test-Path $checkPath -ErrorAction SilentlyContinue
If ($winStat) {
$winAbs = (Resolve-Path $checkPath).Path
}
# Use Go program
$goAbs = & $mystat $checkPath
$goStat = $LastExitCode -eq 0
[PSCustomObject]@{
# compare results
status = (($winStat -eq $goStat) -and ($winAbs -eq $goAbs))
cwd = $cwd
driveCwd = $driveCwd
path = $checkPath
winStat = $winStat
goStat = $goStat
winAbs = $winAbs
goAbs = $goAbs
}
}
}
} |
Reference: https://discourse.gohugo.io/t/linux-hugo-for-ubuntu-renders-one-page-less-than-windows-version-from-mounted-folder/49664/7?u=jmooring
On Windows, if a mount path has a leading slash, and that path exists relative to the root of the project directory, Hugo finds the path in the project directory and mounts the directory when it shouldn't. Paths with leading slashes are supposed to be relative to the system root.
The text was updated successfully, but these errors were encountered: