mirror of
https://github.com/go-gitea/gitea
synced 2024-07-07 10:35:48 +00:00
* Dropped unused codekit config * Integrated dynamic and static bindata for public * Ignore public bindata * Add a general generate make task * Integrated flexible public assets into web command * Updated vendoring, added all missiong govendor deps * Made the linter happy with the bindata and dynamic code * Moved public bindata definition to modules directory * Ignoring the new bindata path now * Updated to the new public modules import path * Updated public bindata command and drop the new prefix
66 lines
1.1 KiB
Go
66 lines
1.1 KiB
Go
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
|
|
// All rights reserved.
|
|
//
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
package storage
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
type plan9FileLock struct {
|
|
f *os.File
|
|
}
|
|
|
|
func (fl *plan9FileLock) release() error {
|
|
return fl.f.Close()
|
|
}
|
|
|
|
func newFileLock(path string, readOnly bool) (fl fileLock, err error) {
|
|
var (
|
|
flag int
|
|
perm os.FileMode
|
|
)
|
|
if readOnly {
|
|
flag = os.O_RDONLY
|
|
} else {
|
|
flag = os.O_RDWR
|
|
perm = os.ModeExclusive
|
|
}
|
|
f, err := os.OpenFile(path, flag, perm)
|
|
if os.IsNotExist(err) {
|
|
f, err = os.OpenFile(path, flag|os.O_CREATE, perm|0644)
|
|
}
|
|
if err != nil {
|
|
return
|
|
}
|
|
fl = &plan9FileLock{f: f}
|
|
return
|
|
}
|
|
|
|
func rename(oldpath, newpath string) error {
|
|
if _, err := os.Stat(newpath); err == nil {
|
|
if err := os.Remove(newpath); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
_, fname := filepath.Split(newpath)
|
|
return os.Rename(oldpath, fname)
|
|
}
|
|
|
|
func syncDir(name string) error {
|
|
f, err := os.Open(name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
if err := f.Sync(); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|