grim/hgkeeper
Clone
Summary
Browse
Changes
Graph
Remove the mercurial 6.1 pin from the container image
23 months ago, Gary Kramlich
653b933ba715
Remove the mercurial 6.1 pin from the container image
package
access
import
(
"fmt"
"os"
"path"
"path/filepath"
"strings"
)
func
refreshHgWeb
()
error
{
fp
,
err
:=
os
.
OpenFile
(
hgwebConfigPath
,
os
.
O_WRONLY
|
os
.
O_TRUNC
,
0644
)
if
err
!=
nil
{
return
err
}
defer
fp
.
Close
()
fmt
.
Fprintf
(
fp
,
"[paths]\n"
)
absReposPath
,
err
:=
filepath
.
Abs
(
ReposPath
())
if
err
!=
nil
{
return
err
}
// walk the reposPath, looking for .hg directories, when one is found,
// check if it is publicly readable, and if so, add it to the config file.
filepath
.
Walk
(
absReposPath
,
func
(
filename
string
,
info
os
.
FileInfo
,
err
error
)
error
{
// check if we're looking at a directory
if
!
info
.
IsDir
()
{
return
nil
}
// check if it is a .hg directory
if
!
strings
.
HasSuffix
(
info
.
Name
(),
".hg"
)
{
return
nil
}
// figure out the repo path that we will be checking against the casbin
// stuff. That means it needs to be the exact path of the repo and not
// include the parent directory.
repoPath
:=
path
.
Dir
(
filename
)
relativeRepoPath
:=
strings
.
TrimPrefix
(
repoPath
,
absReposPath
)
// check if it's publicly readable
if
CanRead
(
"public"
,
relativeRepoPath
)
{
fmt
.
Fprintf
(
fp
,
"%s = %s\n"
,
relativeRepoPath
,
repoPath
)
}
return
filepath
.
SkipDir
})
return
nil
}