mirror of
https://github.com/cloudreve/cloudreve.git
synced 2025-11-03 04:15:59 +08:00
Init V4 community edition (#2265)
* Init V4 community edition * Init V4 community edition
This commit is contained in:
@ -22,7 +22,6 @@ func CreatNestedFile(path string) (*os.File, error) {
|
||||
if !Exists(basePath) {
|
||||
err := os.MkdirAll(basePath, 0700)
|
||||
if err != nil {
|
||||
Log().Warning("Failed to create directory: %s", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@ -30,6 +29,19 @@ func CreatNestedFile(path string) (*os.File, error) {
|
||||
return os.Create(path)
|
||||
}
|
||||
|
||||
// CreatNestedFolder creates a folder with the given path, if the directory does not exist,
|
||||
// it will be created recursively.
|
||||
func CreatNestedFolder(path string) error {
|
||||
if !Exists(path) {
|
||||
err := os.MkdirAll(path, 0700)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsEmpty 返回给定目录是否为空目录
|
||||
func IsEmpty(name string) (bool, error) {
|
||||
f, err := os.Open(name)
|
||||
@ -44,3 +56,21 @@ func IsEmpty(name string) (bool, error) {
|
||||
}
|
||||
return false, err // Either not empty or error, suits both cases
|
||||
}
|
||||
|
||||
type CallbackReader struct {
|
||||
reader io.Reader
|
||||
callback func(int64)
|
||||
}
|
||||
|
||||
func NewCallbackReader(reader io.Reader, callback func(int64)) *CallbackReader {
|
||||
return &CallbackReader{
|
||||
reader: reader,
|
||||
callback: callback,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *CallbackReader) Read(p []byte) (n int, err error) {
|
||||
n, err = r.reader.Read(p)
|
||||
r.callback(int64(n))
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user