mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-07-27 18:30:34 +00:00

The defaults remain the same as before. For now, the config options are global instead of per-user. Note also that the BoltDB creation maintains the old default mode of 0640 since it's not really a user-facing filesystem manipulation. Fixes #5316, #5200
41 lines
718 B
Go
41 lines
718 B
Go
package fileutils
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"path"
|
|
|
|
"github.com/spf13/afero"
|
|
)
|
|
|
|
// Copy copies a file or folder from one place to another.
|
|
func Copy(afs afero.Fs, src, dst string, fileMode, dirMode fs.FileMode) error {
|
|
if src = path.Clean("/" + src); src == "" {
|
|
return os.ErrNotExist
|
|
}
|
|
|
|
if dst = path.Clean("/" + dst); dst == "" {
|
|
return os.ErrNotExist
|
|
}
|
|
|
|
if src == "/" || dst == "/" {
|
|
// Prohibit copying from or to the virtual root directory.
|
|
return os.ErrInvalid
|
|
}
|
|
|
|
if dst == src {
|
|
return os.ErrInvalid
|
|
}
|
|
|
|
info, err := afs.Stat(src)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if info.IsDir() {
|
|
return CopyDir(afs, src, dst, fileMode, dirMode)
|
|
}
|
|
|
|
return CopyFile(afs, src, dst, fileMode, dirMode)
|
|
}
|