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

Cuonglm/issue 1 #2

Merged
merged 3 commits into from
Dec 23, 2019
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion cmd/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"time"

"github.com/urfave/cli"

"code.gitea.io/gitea/modules/fs"
)

// CmdCert represents the available cert sub-command.
Expand Down Expand Up @@ -180,7 +182,7 @@ func runCert(c *cli.Context) error {
}
log.Println("Written cert.pem")

keyOut, err := os.OpenFile("key.pem", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
keyOut, err := fs.AppFs.OpenFile("key.pem", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
log.Fatalf("Failed to open key.pem for writing: %v", err)
}
Expand Down
13 changes: 7 additions & 6 deletions cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/fs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"

Expand Down Expand Up @@ -70,7 +71,7 @@ func runDump(ctx *cli.Context) error {
}

tmpDir := ctx.String("tempdir")
if _, err := os.Stat(tmpDir); os.IsNotExist(err) {
if _, err := fs.AppFs.Stat(tmpDir); os.IsNotExist(err) {
fatal("Path does not exist: %s", tmpDir)
}
tmpWorkDir, err := ioutil.TempDir(tmpDir, "gitea-dump-")
Expand Down Expand Up @@ -130,7 +131,7 @@ func runDump(ctx *cli.Context) error {
}
}

customDir, err := os.Stat(setting.CustomPath)
customDir, err := fs.AppFs.Stat(setting.CustomPath)
if err == nil && customDir.IsDir() {
if err := z.AddDir("custom", setting.CustomPath); err != nil {
fatal("Failed to include custom: %v", err)
Expand All @@ -156,17 +157,17 @@ func runDump(ctx *cli.Context) error {
}

if err = z.Close(); err != nil {
_ = os.Remove(fileName)
_ = fs.AppFs.Remove(fileName)
fatal("Failed to save %s: %v", fileName, err)
}

if err := os.Chmod(fileName, 0600); err != nil {
if err := fs.AppFs.Chmod(fileName, 0600); err != nil {
log.Info("Can't change file access permissions mask to 0600: %v", err)
}

log.Info("Removing tmp work dir: %s", tmpWorkDir)

if err := os.RemoveAll(tmpWorkDir); err != nil {
if err := fs.AppFs.RemoveAll(tmpWorkDir); err != nil {
fatal("Failed to remove %s: %v", tmpWorkDir, err)
}
log.Info("Finish dumping in file %s", fileName)
Expand All @@ -180,7 +181,7 @@ func zipAddDirectoryExclude(zip *zip.ZipArchive, zipPath, absPath string, exclud
if err != nil {
return err
}
dir, err := os.Open(absPath)
dir, err := fs.AppFs.Open(absPath)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"time"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/fs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/pprof"
"code.gitea.io/gitea/modules/private"
Expand Down Expand Up @@ -140,7 +141,7 @@ func runServ(c *cli.Context) error {
reponame := strings.ToLower(strings.TrimSuffix(rr[1], ".git"))

if setting.EnablePprof || c.Bool("enable-pprof") {
if err := os.MkdirAll(setting.PprofDataPath, os.ModePerm); err != nil {
if err := fs.AppFs.MkdirAll(setting.PprofDataPath, os.ModePerm); err != nil {
fail("Error while trying to create PPROF_DATA_PATH", "Error while trying to create PPROF_DATA_PATH: %v", err)
}

Expand Down Expand Up @@ -194,7 +195,7 @@ func runServ(c *cli.Context) error {
os.Setenv(models.EnvIsDeployKey, fmt.Sprintf("%t", results.IsDeployKey))
os.Setenv(models.EnvKeyID, fmt.Sprintf("%d", results.KeyID))

//LFS token authentication
// LFS token authentication
if verb == lfsAuthenticateVerb {
url := fmt.Sprintf("%s%s/%s.git/info/lfs", setting.AppURL, url.PathEscape(results.OwnerName), url.PathEscape(results.RepoName))

Expand Down
51 changes: 26 additions & 25 deletions contrib/pr/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/fs"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/external"
"code.gitea.io/gitea/modules/setting"
Expand Down Expand Up @@ -78,7 +79,7 @@ func runPR() {

log.Printf("[PR] Loading fixtures data ...\n")
setting.CheckLFSVersion()
//models.LoadConfigs()
// models.LoadConfigs()
/*
setting.Database.Type = "sqlite3"
setting.Database.Path = ":memory:"
Expand All @@ -90,14 +91,14 @@ func runPR() {

routers.NewServices()
setting.Database.LogSQL = true
//x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
// x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")

var helper testfixtures.Helper = &testfixtures.SQLite{}
models.NewEngine(context.Background(), func(_ *xorm.Engine) error {
return nil
})
models.HasEngine = true
//x.ShowSQL(true)
// x.ShowSQL(true)
err = models.InitFixtures(
helper,
path.Join(curDir, "models/fixtures/"),
Expand All @@ -107,12 +108,12 @@ func runPR() {
os.Exit(1)
}
models.LoadFixtures()
os.RemoveAll(setting.RepoRootPath)
os.RemoveAll(models.LocalCopyPath())
fs.AppFs.RemoveAll(setting.RepoRootPath)
fs.AppFs.RemoveAll(models.LocalCopyPath())
com.CopyDir(path.Join(curDir, "integrations/gitea-repositories-meta"), setting.RepoRootPath)

log.Printf("[PR] Setting up router\n")
//routers.GlobalInit()
// routers.GlobalInit()
external.RegisterParsers()
markup.Init()
m := routes.NewMacaron()
Expand All @@ -135,25 +136,25 @@ func runPR() {
}
*/

//Start the server
// Start the server
http.ListenAndServe(":8080", context2.ClearHandler(m))

log.Printf("[PR] Cleaning up ...\n")
/*
if err = os.RemoveAll(setting.Indexer.IssuePath); err != nil {
fmt.Printf("os.RemoveAll: %v\n", err)
if err = fs.AppFs.RemoveAll(setting.Indexer.IssuePath); err != nil {
fmt.Printf("fs.AppFs.RemoveAll: %v\n", err)
os.Exit(1)
}
if err = os.RemoveAll(setting.Indexer.RepoPath); err != nil {
if err = fs.AppFs.RemoveAll(setting.Indexer.RepoPath); err != nil {
fmt.Printf("Unable to remove repo indexer: %v\n", err)
os.Exit(1)
}
*/
if err = os.RemoveAll(setting.RepoRootPath); err != nil {
log.Fatalf("os.RemoveAll: %v\n", err)
if err = fs.AppFs.RemoveAll(setting.RepoRootPath); err != nil {
log.Fatalf("fs.AppFs.RemoveAll: %v\n", err)
}
if err = os.RemoveAll(setting.AppDataPath); err != nil {
log.Fatalf("os.RemoveAll: %v\n", err)
if err = fs.AppFs.RemoveAll(setting.AppDataPath); err != nil {
log.Fatalf("fs.AppFs.RemoveAll: %v\n", err)
}
}

Expand All @@ -171,15 +172,15 @@ func main() {
force = false
}

//Otherwise checkout PR
// Otherwise checkout PR
if len(os.Args) != 2 {
log.Fatal("Need only one arg: the PR number")
}
pr := os.Args[1]

codeFilePath = filepath.FromSlash(codeFilePath) //Convert to running OS
codeFilePath = filepath.FromSlash(codeFilePath) // Convert to running OS

//Copy this file if it will not exist in the PR branch
// Copy this file if it will not exist in the PR branch
dat, err := ioutil.ReadFile(codeFilePath)
if err != nil {
log.Fatalf("Failed to cache this code file : %v", err)
Expand All @@ -190,14 +191,14 @@ func main() {
log.Fatalf("Failed to open the repo : %v", err)
}

//Find remote upstream
// Find remote upstream
remotes, err := repo.Remotes()
if err != nil {
log.Fatalf("Failed to list remotes of repo : %v", err)
}
remoteUpstream := "origin" //Default
remoteUpstream := "origin" // Default
for _, r := range remotes {
if r.Config().URLs[0] == "https://github.com/go-gitea/gitea" || r.Config().URLs[0] == "[email protected]:go-gitea/gitea.git" { //fetch at index 0
if r.Config().URLs[0] == "https://github.com/go-gitea/gitea" || r.Config().URLs[0] == "[email protected]:go-gitea/gitea.git" { // fetch at index 0
remoteUpstream = r.Config().Name
break
}
Expand All @@ -208,7 +209,7 @@ func main() {

log.Printf("Fetching PR #%s in %s\n", pr, branch)
if runtime.GOOS == "windows" {
//Use git cli command for windows
// Use git cli command for windows
runCmd("git", "fetch", remoteUpstream, fmt.Sprintf("pull/%s/head:%s", pr, branch))
} else {
ref := fmt.Sprintf("refs/pull/%s/head:%s", pr, branchRef)
Expand Down Expand Up @@ -236,9 +237,9 @@ func main() {
log.Fatalf("Failed to checkout %s : %v", branch, err)
}

//Copy this file if not exist
if _, err := os.Stat(codeFilePath); os.IsNotExist(err) {
err = os.MkdirAll(filepath.Dir(codeFilePath), 0755)
// Copy this file if not exist
if _, err := fs.AppFs.Stat(codeFilePath); os.IsNotExist(err) {
err = fs.AppFs.MkdirAll(filepath.Dir(codeFilePath), 0755)
if err != nil {
log.Fatalf("Failed to duplicate this code file in PR : %v", err)
}
Expand All @@ -248,7 +249,7 @@ func main() {
}
}
time.Sleep(5 * time.Second)
//Start with integration test
// Start with integration test
runCmd("go", "run", "-tags", "sqlite sqlite_unlock_notify", codeFilePath, "-run")
}
func runCmd(cmd ...string) {
Expand Down
6 changes: 6 additions & 0 deletions custom/conf/app.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -918,3 +918,9 @@ QUEUE_CONN_STR = "addrs=127.0.0.1:6379 db=0"
MAX_ATTEMPTS = 3
; Backoff time per http/https request retry (seconds)
RETRY_BACKOFF = 3

[storage]
; URL of bucket where files are stored (such as attachments, avatars, etc.).
; If unset, `BUCKET_URL` defaults to `file:// <AppWorkPath>`.
; Consult https://gocloud.dev/howto/blob for URL format for various cloud providers and their credential paths and env variables.
BUCKET_URL =
2 changes: 1 addition & 1 deletion docs/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trim_trailing_whitespace = true
indent_style = tab
indent_size = 8

[*.{tmpl,html}]
[*.{tmpl, html}]
indent_style = tab
indent_size = 4

Expand Down
4 changes: 4 additions & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ You may redefine `ELEMENT`, `ALLOW_ATTR`, and `REGEXP` multiple times; each time
- `MAX_ATTEMPTS`: **3**: Max attempts per http/https request on migrations.
- `RETRY_BACKOFF`: **3**: Backoff time per http/https request retry (seconds)

## Storage (`storage`)

- `BUCKET_URL`: URL of bucket where files are stored (such as attachments, avatars, etc.). If unset, `BUCKET_URL` defaults to `file:// <AppWorkPath>`. Consult https://gocloud.dev/howto/blob for URL format for various cloud providers and their credential paths and env variables.

## Other (`other`)

- `SHOW_FOOTER_BRANDING`: **false**: Show Gitea branding in the footer.
Expand Down
4 changes: 4 additions & 0 deletions docs/content/doc/advanced/config-cheat-sheet.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ IS_INPUT_FILE = false
- `MAX_ATTEMPTS`: **3**: 在迁移过程中的 http/https 请求重试次数。
- `RETRY_BACKOFF`: **3**: 等待下一次重试的时间,单位秒。

## Storage (`storage`)

- `BUCKET_URL`: 存储文件的存储桶的URL(例如附件,头像等). 如果未设置,`BUCKET_URL`默认为`file:// <AppWorkPath>`. 有关各种云提供商及其凭证路径和env变量的URL格式,请参阅https://gocloud.dev/howto/blob .

## Other (`other`)

- `SHOW_FOOTER_BRANDING`: 为真则在页面底部显示Gitea的字样。
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ require (
github.com/issue9/identicon v0.0.0-20160320065130-d36b54562f4c
github.com/jaytaylor/html2text v0.0.0-20160923191438-8fb95d837f7d
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/joho/godotenv v1.3.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20170619183022-cd60e84ee657
github.com/keybase/go-crypto v0.0.0-20170605145657-00ac4db533f6
github.com/klauspost/compress v1.9.2
Expand All @@ -63,7 +62,7 @@ require (
github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96
github.com/mailru/easyjson v0.7.0 // indirect
github.com/markbates/goth v1.56.0
github.com/mattn/go-isatty v0.0.7
github.com/mattn/go-isatty v0.0.8
github.com/mattn/go-oci8 v0.0.0-20190320171441-14ba190cf52d // indirect
github.com/mattn/go-sqlite3 v1.11.0
github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75
Expand All @@ -85,6 +84,7 @@ require (
github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
github.com/spf13/afero v1.2.2
github.com/steveyen/gtreap v0.0.0-20150807155958-0abe01ef9be2 // indirect
github.com/stretchr/testify v1.4.0
github.com/tecbot/gorocksdb v0.0.0-20181010114359-8752a9433481 // indirect
Expand All @@ -96,6 +96,7 @@ require (
github.com/urfave/cli v1.20.0
github.com/yohcop/openid-go v0.0.0-20160914080427-2c050d2dae53
go.etcd.io/bbolt v1.3.3 // indirect
gocloud.dev v0.16.0
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413
golang.org/x/net v0.0.0-20191101175033-0deb6923b6d9
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
Expand Down
Loading