mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-26 02:34:58 +08:00
fix: webdav
This commit is contained in:
@@ -38,23 +38,32 @@ func NewWebdavStorage(url, user, password string) (*WebdavStorage, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *WebdavStorage) Move(local, remote string) error {
|
func (w *WebdavStorage) Move(local, remote string) error {
|
||||||
|
baseLocal := filepath.Base(local)
|
||||||
|
|
||||||
err := filepath.Walk(local, func(path string, info fs.FileInfo, err error) error {
|
err := filepath.Walk(local, func(path string, info fs.FileInfo, err error) error {
|
||||||
name := filepath.Join(remote, info.Name())
|
if err != nil {
|
||||||
localName := filepath.Join(local, info.Name())
|
return errors.Wrapf(err, "read file %v", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
rel, err := filepath.Rel(local, path)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "path relation")
|
||||||
|
}
|
||||||
|
remoteName := filepath.Join(remote, baseLocal, rel)
|
||||||
|
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
|
|
||||||
if err := w.fs.Mkdir(context.TODO(), name); err != nil {
|
if err := w.fs.Mkdir(context.TODO(), remoteName); err != nil {
|
||||||
return errors.Wrapf(err, "mkdir %v", name)
|
return errors.Wrapf(err, "mkdir %v", remoteName)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { //is file
|
} else { //is file
|
||||||
if writer, err := w.fs.Create(context.TODO(), name); err != nil {
|
if writer, err := w.fs.Create(context.TODO(), remoteName); err != nil {
|
||||||
return errors.Wrapf(err, "create file %s", name)
|
return errors.Wrapf(err, "create file %s", remoteName)
|
||||||
} else {
|
} else {
|
||||||
defer writer.Close()
|
defer writer.Close()
|
||||||
if f, err := os.OpenFile(localName, os.O_RDONLY, 0666); err != nil {
|
if f, err := os.OpenFile(path, os.O_RDONLY, 0666); err != nil {
|
||||||
return errors.Wrapf(err, "read file %v", localName)
|
return errors.Wrapf(err, "read file %v", path)
|
||||||
} else { //open success
|
} else { //open success
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
_, err := io.Copy(writer, f)
|
_, err := io.Copy(writer, f)
|
||||||
@@ -64,7 +73,7 @@ func (w *WebdavStorage) Move(local, remote string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Infof("file copy complete: %d", name)
|
log.Infof("file copy complete: %d", remoteName)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user