Browse Source

models/repo: handle deletion on Windows (#4152)

pull/4155/head
Unknwon 8 years ago
parent
commit
40fbe7fa8e
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 2
      models/admin.go
  2. 14
      models/repo.go
  3. 2
      templates/mail/auth/activate.tmpl
  4. 2
      templates/mail/auth/activate_email.tmpl
  5. 2
      templates/mail/auth/register_notify.tmpl
  6. 2
      templates/mail/auth/reset_passwd.tmpl

2
models/admin.go

@ -74,7 +74,7 @@ func CreateRepositoryNotice(desc string) error {
// creates a system notice when error occurs. // creates a system notice when error occurs.
func RemoveAllWithNotice(title, path string) { func RemoveAllWithNotice(title, path string) {
var err error var err error
// workaround for Go not being able to remove read-only files/folders: https://github.com/golang/go/issues/9606 // LEGACY [Go 1.7]: workaround for Go not being able to remove read-only files/folders: https://github.com/golang/go/issues/9606
// this bug should be fixed on Go 1.7, so the workaround should be removed when Gogs don't support Go 1.6 anymore: // this bug should be fixed on Go 1.7, so the workaround should be removed when Gogs don't support Go 1.6 anymore:
// https://github.com/golang/go/commit/2ffb3e5d905b5622204d199128dec06cefd57790 // https://github.com/golang/go/commit/2ffb3e5d905b5622204d199128dec06cefd57790
// Note: Windows complains when delete target does not exist, therefore we can skip deletion in such cases. // Note: Windows complains when delete target does not exist, therefore we can skip deletion in such cases.

14
models/repo.go

@ -643,7 +643,7 @@ func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) {
migrateTimeout := time.Duration(setting.Git.Timeout.Migrate) * time.Second migrateTimeout := time.Duration(setting.Git.Timeout.Migrate) * time.Second
os.RemoveAll(repoPath) RemoveAllWithNotice("Repository path erase before creation", repoPath)
if err = git.Clone(opts.RemoteAddr, repoPath, git.CloneRepoOptions{ if err = git.Clone(opts.RemoteAddr, repoPath, git.CloneRepoOptions{
Mirror: true, Mirror: true,
Quiet: true, Quiet: true,
@ -654,14 +654,14 @@ func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) {
wikiRemotePath := wikiRemoteURL(opts.RemoteAddr) wikiRemotePath := wikiRemoteURL(opts.RemoteAddr)
if len(wikiRemotePath) > 0 { if len(wikiRemotePath) > 0 {
os.RemoveAll(wikiPath) RemoveAllWithNotice("Repository wiki path erase before creation", repoPath)
if err = git.Clone(wikiRemotePath, wikiPath, git.CloneRepoOptions{ if err = git.Clone(wikiRemotePath, wikiPath, git.CloneRepoOptions{
Mirror: true, Mirror: true,
Quiet: true, Quiet: true,
Timeout: migrateTimeout, Timeout: migrateTimeout,
}); err != nil { }); err != nil {
log.Trace("Fail to clone wiki: %v", err) log.Trace("Fail to clone wiki: %v", err)
os.RemoveAll(wikiPath) RemoveAllWithNotice("Delete repository wiki for initialization failure", repoPath)
} }
} }
@ -890,7 +890,7 @@ func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts C
// Initialize repository according to user's choice. // Initialize repository according to user's choice.
if opts.AutoInit { if opts.AutoInit {
os.MkdirAll(tmpDir, os.ModePerm) os.MkdirAll(tmpDir, os.ModePerm)
defer os.RemoveAll(tmpDir) defer RemoveAllWithNotice("Delete repository for auto-initialization", tmpDir)
if err = prepareRepoCommit(repo, tmpDir, repoPath, opts); err != nil { if err = prepareRepoCommit(repo, tmpDir, repoPath, opts); err != nil {
return fmt.Errorf("prepareRepoCommit: %v", err) return fmt.Errorf("prepareRepoCommit: %v", err)
@ -1009,11 +1009,7 @@ func CreateRepository(u *User, opts CreateRepoOptions) (_ *Repository, err error
if !opts.IsMirror { if !opts.IsMirror {
repoPath := RepoPath(u.Name, repo.Name) repoPath := RepoPath(u.Name, repo.Name)
if err = initRepository(sess, repoPath, u, repo, opts); err != nil { if err = initRepository(sess, repoPath, u, repo, opts); err != nil {
if err2 := os.RemoveAll(repoPath); err2 != nil { RemoveAllWithNotice("Delete repository for initialization failure", repoPath)
log.Error(4, "initRepository: %v", err)
return nil, fmt.Errorf(
"delete repo directory %s/%s failed(2): %v", u.Name, repo.Name, err2)
}
return nil, fmt.Errorf("initRepository: %v", err) return nil, fmt.Errorf("initRepository: %v", err)
} }

2
templates/mail/auth/activate.tmpl

@ -10,6 +10,6 @@
<p>Please click the following link to verify your e-mail address within <b>{{.ActiveCodeLives}} hours</b>:</p> <p>Please click the following link to verify your e-mail address within <b>{{.ActiveCodeLives}} hours</b>:</p>
<p><a href="{{AppUrl}}user/activate?code={{.Code}}">{{AppUrl}}user/activate?code={{.Code}}</a></p> <p><a href="{{AppUrl}}user/activate?code={{.Code}}">{{AppUrl}}user/activate?code={{.Code}}</a></p>
<p>Not working? Try copying and pasting it to your browser.</p> <p>Not working? Try copying and pasting it to your browser.</p>
<p>© 2016 <a target="_blank" href="{{AppUrl}}">{{AppName}}</a></p> <p>© 2017 <a target="_blank" href="{{AppUrl}}">{{AppName}}</a></p>
</body> </body>
</html> </html>

2
templates/mail/auth/activate_email.tmpl

@ -10,6 +10,6 @@
<p>Please click the following link to verify your email address within <b>{{.ActiveCodeLives}} hours</b>:</p> <p>Please click the following link to verify your email address within <b>{{.ActiveCodeLives}} hours</b>:</p>
<p><a href="{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}">{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}</a></p> <p><a href="{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}">{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}</a></p>
<p>Not working? Try copying and pasting it to your browser.</p> <p>Not working? Try copying and pasting it to your browser.</p>
<p>© 2016 <a target="_blank" href="{{AppUrl}}">{{AppName}}</a></p> <p>© 2017 <a target="_blank" href="{{AppUrl}}">{{AppName}}</a></p>
</body> </body>
</html> </html>

2
templates/mail/auth/register_notify.tmpl

@ -9,6 +9,6 @@
<p>Hi <b>{{.Username}}</b>, this is your registration confirmation email for {{AppName}}!</p> <p>Hi <b>{{.Username}}</b>, this is your registration confirmation email for {{AppName}}!</p>
<p>You can now login via username: {{.Username}}.</p> <p>You can now login via username: {{.Username}}.</p>
<p><a href="{{AppUrl}}user/login">{{AppUrl}}user/login</a></p> <p><a href="{{AppUrl}}user/login">{{AppUrl}}user/login</a></p>
<p>© 2016 <a target="_blank" href="{{AppUrl}}">{{AppName}}</a></p> <p>© 2017 <a target="_blank" href="{{AppUrl}}">{{AppName}}</a></p>
</body> </body>
</html> </html>

2
templates/mail/auth/reset_passwd.tmpl

@ -10,6 +10,6 @@
<p>Please click the following link to verify your email address within <b>{{.ResetPwdCodeLives}} hours</b>:</p> <p>Please click the following link to verify your email address within <b>{{.ResetPwdCodeLives}} hours</b>:</p>
<p><a href="{{AppUrl}}user/reset_password?code={{.Code}}">{{AppUrl}}user/reset_password?code={{.Code}}</a></p> <p><a href="{{AppUrl}}user/reset_password?code={{.Code}}">{{AppUrl}}user/reset_password?code={{.Code}}</a></p>
<p>Not working? Try copying and pasting it to your browser.</p> <p>Not working? Try copying and pasting it to your browser.</p>
<p>© 2016 <a target="_blank" href="{{AppUrl}}">{{AppName}}</a></p> <p>© 2017 <a target="_blank" href="{{AppUrl}}">{{AppName}}</a></p>
</body> </body>
</html> </html>

Loading…
Cancel
Save