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

Closed
opened 2025-11-02 03:52:27 -06:00 by GiteaMirror · 3 comments
Owner

Originally created by @MCF on GitHub (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.
Originally created by @MCF on GitHub (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 - [x] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] 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: <em> Package path implements utility routines for manipulating slash-separated paths. <br><br> 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. </em>
GiteaMirror added the type/bug label 2025-11-02 03:52:27 -06:00
Author
Owner

@MCF commented on GitHub (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.

@MCF commented on GitHub (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`: ```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.
Author
Owner

@Morlinest commented on GitHub (Nov 4, 2017):

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

@Morlinest commented on GitHub (Nov 4, 2017): @MCF I have tried this: https://play.golang.org/p/-lnGrBxlM0. Try to use double (escaped) backslashes please.
Author
Owner

@MCF commented on GitHub (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.

@MCF commented on GitHub (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`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#1207