MCPcopy
hub / github.com/OpenListTeam/OpenList / PutURL

Function PutURL

internal/op/fs.go:715–769  ·  view source on GitHub ↗
(ctx context.Context, storage driver.Driver, dstDirPath, dstName, url string)

Source from the content-addressed store, hash-verified

713}
714
715func PutURL(ctx context.Context, storage driver.Driver, dstDirPath, dstName, url string) error {
716 if storage.Config().CheckStatus && storage.GetStorage().Status != WORK {
717 return errors.WithMessagef(errs.StorageNotInit, "storage status: %s", storage.GetStorage().Status)
718 }
719 dstDirPath = utils.FixAndCleanPath(dstDirPath)
720 dstPath := stdpath.Join(dstDirPath, dstName)
721
722 if _, err := Get(ctx, storage, dstPath); err == nil {
723 return errors.WithStack(errs.ObjectAlreadyExists)
724 }
725 err := MakeDir(ctx, storage, dstDirPath)
726 if err != nil {
727 return errors.WithMessagef(err, "failed to make dir [%s]", dstDirPath)
728 }
729 dstDir, err := GetUnwrap(ctx, storage, dstDirPath)
730 if err != nil {
731 return errors.WithMessagef(err, "failed to get dir [%s]", dstDirPath)
732 }
733 if model.ObjHasMask(dstDir, model.NoWrite) {
734 return errors.WithStack(errs.PermissionDenied)
735 }
736 var newObj model.Obj
737 switch s := storage.(type) {
738 case driver.PutURLResult:
739 newObj, err = s.PutURL(ctx, dstDir, dstName, url)
740 case driver.PutURL:
741 err = s.PutURL(ctx, dstDir, dstName, url)
742 default:
743 return errors.WithStack(errs.NotImplement)
744 }
745 if err == nil {
746 Cache.linkCache.DeleteKey(Key(storage, dstPath))
747 if !storage.Config().NoCache {
748 if cache, exist := Cache.dirCache.Get(Key(storage, dstDirPath)); exist {
749 if newObj == nil {
750 t := time.Now()
751 newObj = &model.Object{
752 Name: dstName,
753 Modified: t,
754 Ctime: t,
755 Mask: model.Temp,
756 }
757 }
758 newObj = wrapObjName(storage, newObj)
759 cache.UpdateObject(newObj.GetName(), newObj)
760 }
761
762 if ctx.Value(conf.SkipHookKey) == nil && needHandleObjsUpdateHook() {
763 go objsUpdateHook(context.WithoutCancel(ctx), storage, dstDirPath, false)
764 }
765 }
766 }
767 log.Debugf("put url [%s](%s) done", dstName, url)
768 return errors.WithStack(err)
769}
770
771func GetDirectUploadTools(storage driver.Driver) []string {
772 du, ok := storage.(driver.DirectUploader)

Callers 1

PutURLFunction · 0.92

Calls 15

GetNameMethod · 0.95
FixAndCleanPathFunction · 0.92
ObjHasMaskFunction · 0.92
GetUnwrapFunction · 0.85
KeyFunction · 0.85
wrapObjNameFunction · 0.85
needHandleObjsUpdateHookFunction · 0.85
objsUpdateHookFunction · 0.85
DeleteKeyMethod · 0.80
UpdateObjectMethod · 0.80
GetFunction · 0.70
MakeDirFunction · 0.70

Tested by

no test coverage detected