github.com/fzfile/BaiduPCS-Go@v0.0.0-20200606205115-4408961cf336/baidupcs/cp_mv_rename.go (about)

     1  package baidupcs
     2  
     3  import (
     4  	"github.com/fzfile/BaiduPCS-Go/baidupcs/pcserror"
     5  	"unsafe"
     6  )
     7  
     8  // Rename 重命名文件/目录
     9  func (pcs *BaiduPCS) Rename(from, to string) (pcsError pcserror.Error) {
    10  	return pcs.cpmvOp(OperationRename, &CpMvJSON{
    11  		From: from,
    12  		To:   to,
    13  	})
    14  }
    15  
    16  // Copy 批量拷贝文件/目录
    17  func (pcs *BaiduPCS) Copy(cpmvJSON ...*CpMvJSON) (pcsError pcserror.Error) {
    18  	return pcs.cpmvOp(OperationCopy, cpmvJSON...)
    19  }
    20  
    21  // Move 批量移动文件/目录
    22  func (pcs *BaiduPCS) Move(cpmvJSON ...*CpMvJSON) (pcsError pcserror.Error) {
    23  	return pcs.cpmvOp(OperationMove, cpmvJSON...)
    24  }
    25  
    26  func (pcs *BaiduPCS) cpmvOp(op string, cpmvJSON ...*CpMvJSON) (pcsError pcserror.Error) {
    27  	dataReadCloser, err := pcs.prepareCpMvOp(op, cpmvJSON...)
    28  	if err != nil {
    29  		return
    30  	}
    31  
    32  	defer dataReadCloser.Close()
    33  
    34  	errInfo := pcserror.DecodePCSJSONError(op, dataReadCloser)
    35  	if errInfo != nil {
    36  		return errInfo
    37  	}
    38  
    39  	// 更新缓存
    40  	pcs.deleteCache((*CpMvJSONList)(unsafe.Pointer(&cpmvJSON)).AllRelatedDir())
    41  	return nil
    42  }