|
|
|
@ -60,7 +60,7 @@ func (folder *Folder) GetChildFolder() ([]Folder, error) {
|
|
|
|
|
func GetRecursiveChildFolder(dirs []uint, uid uint, includeSelf bool) ([]Folder, error) {
|
|
|
|
|
folders := make([]Folder, 0, len(dirs))
|
|
|
|
|
var err error
|
|
|
|
|
// SQLite 下使用递归查询
|
|
|
|
|
|
|
|
|
|
var parFolders []Folder
|
|
|
|
|
result := DB.Where("owner_id = ? and id in (?)", uid, dirs).Find(&parFolders)
|
|
|
|
|
if result.Error != nil {
|
|
|
|
@ -139,6 +139,7 @@ func (folder *Folder) MoveOrCopyFileTo(files []uint, dstFolder *Folder, isCopy b
|
|
|
|
|
for _, oldFile := range originFiles {
|
|
|
|
|
oldFile.Model = gorm.Model{}
|
|
|
|
|
oldFile.FolderID = dstFolder.ID
|
|
|
|
|
oldFile.UserID = dstFolder.OwnerID
|
|
|
|
|
|
|
|
|
|
if err := DB.Create(&oldFile).Error; err != nil {
|
|
|
|
|
return copiedSize, err
|
|
|
|
@ -203,6 +204,7 @@ func (folder *Folder) CopyFolderTo(folderID uint, dstFolder *Folder) (size uint6
|
|
|
|
|
oldID := folder.ID
|
|
|
|
|
folder.Model = gorm.Model{}
|
|
|
|
|
folder.ParentID = &newID
|
|
|
|
|
folder.OwnerID = dstFolder.OwnerID
|
|
|
|
|
if err = DB.Create(&folder).Error; err != nil {
|
|
|
|
|
return size, err
|
|
|
|
|
}
|
|
|
|
@ -225,7 +227,7 @@ func (folder *Folder) CopyFolderTo(folderID uint, dstFolder *Folder) (size uint6
|
|
|
|
|
for _, oldFile := range originFiles {
|
|
|
|
|
oldFile.Model = gorm.Model{}
|
|
|
|
|
oldFile.FolderID = newIDCache[oldFile.FolderID]
|
|
|
|
|
|
|
|
|
|
oldFile.UserID = dstFolder.OwnerID
|
|
|
|
|
if err := DB.Create(&oldFile).Error; err != nil {
|
|
|
|
|
return size, err
|
|
|
|
|
}
|
|
|
|
@ -262,40 +264,6 @@ func (folder *Folder) Rename(new string) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CopyChildFrom 将给定文件和拷贝至自身,并更改所有者ID
|
|
|
|
|
func (folder *Folder) CopyChildFrom(folders []Folder, files []File) error {
|
|
|
|
|
// 开启事务
|
|
|
|
|
tx := DB.Begin()
|
|
|
|
|
defer func() {
|
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
|
tx.Rollback()
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// 记录文件父目录对应复制的新目录ID
|
|
|
|
|
var newParent = make(map[uint]uint, len(folders))
|
|
|
|
|
|
|
|
|
|
// TODO 复制目录结构
|
|
|
|
|
|
|
|
|
|
// 复制子文件
|
|
|
|
|
for _, file := range files {
|
|
|
|
|
file.ID = 0
|
|
|
|
|
file.UserID = folder.OwnerID
|
|
|
|
|
if newParentID, ok := newParent[file.FolderID]; ok {
|
|
|
|
|
file.FolderID = newParentID
|
|
|
|
|
} else {
|
|
|
|
|
file.FolderID = folder.ID
|
|
|
|
|
}
|
|
|
|
|
if err := tx.Create(&file).Error; err != nil {
|
|
|
|
|
tx.Rollback()
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tx.Commit().Error
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
实现 FileInfo.FileInfo 接口
|
|
|
|
|
TODO 测试
|
|
|
|
|