Skip to content
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 UNC paths do not work for some config settings #2845

Closed
2 of 7 tasks
MCF opened this issue Nov 3, 2017 · 3 comments · Fixed by #2846
Closed
2 of 7 tasks

Windows UNC paths do not work for some config settings #2845

MCF opened this issue Nov 3, 2017 · 3 comments · Fixed by #2846
Labels
Milestone

Comments

@MCF
Copy link
Contributor

MCF commented Nov 3, 2017

  • Gitea version (or commit ref): 1.2.3
  • Git version: 2.15.0
  • Operating system: Windows Server 2012 & Windows 7
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log message:

Something like:

2017/11/03 13:22:19 [...ules/context/repo.go:335 func1()] [E] RepoAssignment Invalid repo \mycifsserver\mywindowsshare\repositories\orgname\reponame.git: no such file or directory

Description

It is impossible to use windows UNC names (aka windows file shares) in the repository ROOT setting. The UNC name has the double slashes at the start converted to a single slash. For example:

[repository]
ROOT = //mycifsserver/mywindowsshare/repositories

Will be converted into:

\mycifsserver\mywindowsshare\repositories

I've inspected the code and the path package is used in many places to Clean or Join paths, including where the ROOT setting is read. path will not do the right thing on Windows, instead filepath should be used. From the docs for path:

Package path implements utility routines for manipulating slash-separated paths.

The path package should only be used for paths separated by forward slashes, such as the paths in URLs. This package does not deal with Windows paths with drive letters or backslashes; to manipulate operating system paths, use the path/filepath package.
@lafriks lafriks added this to the 1.x.x milestone Nov 3, 2017
@MCF
Copy link
Contributor Author

MCF commented Nov 3, 2017

I've done a bit more digging and think that we could get away with only fixing the one call to path.Clean in the code base. It is in modules/setting/setting.go:

        RepoRootPath = path.Clean(RepoRootPath)

I've experimented a bit and go is very forgiving when it comes to accessing file shares. You can specify either slash (forward or backward) as long as there are two at the start of the UNC server name. And you can mix slashes within a path. So all of these work, and point to the same file:

//mycifsserver/mywindowsshare/test.txt
\\mycifsserver\mywindowsshare\test.txt
//mycifsserver/mywindowsshare\test.txt

It is the call to path.Clean I noted above that is causing the problem.

I think we can ignore wherever path.Join is being used for creating filesystem paths, even for windows.

@Morlinest
Copy link
Member

Morlinest commented Nov 4, 2017

@MCF I have tried this: https://play.golang.org/p/-lnGrBxlM0. Try to use double (escaped) backslashes please.

@MCF
Copy link
Contributor Author

MCF commented Nov 4, 2017

@Morlinest I did try that when I first encoutered the problem. Unfortunately you cannot use backslashes in app.ini. Only front slashes are allowed. See the forcePathSeparator function in modules/setting/setting.go.

@lunny lunny modified the milestones: 1.x.x, 1.3.0 Nov 5, 2017
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants