From a62808588510dee810b706cbd2e19f355e488576 Mon Sep 17 00:00:00 2001 From: Alex Aizman Date: Wed, 6 Dec 2023 21:20:49 -0500 Subject: [PATCH] follow up Signed-off-by: Alex Aizman --- ais/tgttxn.go | 4 ++-- cmd/cli/go.mod | 2 +- cmd/cli/go.sum | 4 ++-- cmn/common.go | 35 ----------------------------------- xact/xs/dpromote.go | 36 +++++++++++++++++++++++++++++++++++- 5 files changed, 40 insertions(+), 41 deletions(-) diff --git a/ais/tgttxn.go b/ais/tgttxn.go index dba3b45653e..40c925294db 100644 --- a/ais/tgttxn.go +++ b/ais/tgttxn.go @@ -904,7 +904,7 @@ func (t *target) promote(c *txnServerCtx, hdr http.Header) (string, error) { return "", err } if !finfo.IsDir() { - txn := newTxnPromote(c, prmMsg, []string{srcFQN}, "", 1) + txn := newTxnPromote(c, prmMsg, []string{srcFQN}, "" /*dirFQN*/, 1) if err := t.transactions.begin(txn); err != nil { return "", err } @@ -1017,7 +1017,7 @@ func prmScan(dirFQN string, prmMsg *cluster.PromoteArgs) (fqns []string, totalN func (t *target) prmNumFiles(c *txnServerCtx, txnPrm *txnPromote, confirmedFshare bool) error { smap := t.owner.smap.Get() for _, fqn := range txnPrm.fqns { - objName, err := cmn.PromotedObjDstName(fqn, txnPrm.dirFQN, txnPrm.msg.ObjName) + objName, err := xs.PrmObjName(fqn, txnPrm.dirFQN, txnPrm.msg.ObjName) if err != nil { return err } diff --git a/cmd/cli/go.mod b/cmd/cli/go.mod index f7af156fe72..e2afa3ad44e 100644 --- a/cmd/cli/go.mod +++ b/cmd/cli/go.mod @@ -4,7 +4,7 @@ go 1.21 // direct require ( - github.com/NVIDIA/aistore v1.3.22-0.20231206174342-7ad18b6fb196 + github.com/NVIDIA/aistore v1.3.22-0.20231206200848-2f4dc8789da0 github.com/fatih/color v1.16.0 github.com/json-iterator/go v1.1.12 github.com/onsi/ginkgo v1.16.5 diff --git a/cmd/cli/go.sum b/cmd/cli/go.sum index 1f69a02af18..7654d787519 100644 --- a/cmd/cli/go.sum +++ b/cmd/cli/go.sum @@ -1,7 +1,7 @@ code.cloudfoundry.org/bytefmt v0.0.0-20190710193110-1eb035ffe2b6/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= -github.com/NVIDIA/aistore v1.3.22-0.20231206174342-7ad18b6fb196 h1:cJPWF48JTT94VwovBs7PBpa8eLCPQ5K2pU90xOVApSg= -github.com/NVIDIA/aistore v1.3.22-0.20231206174342-7ad18b6fb196/go.mod h1:cOTgDt5fVCQOB+rnvYZgVFRF3dEzPqu8f22F3F+Yvtg= +github.com/NVIDIA/aistore v1.3.22-0.20231206200848-2f4dc8789da0 h1:IBAJFfHJ1V8aNvTYTzJ1nEGPcNfjd3BnoyK+hz1CTmc= +github.com/NVIDIA/aistore v1.3.22-0.20231206200848-2f4dc8789da0/go.mod h1:cOTgDt5fVCQOB+rnvYZgVFRF3dEzPqu8f22F3F+Yvtg= github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8= github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q= github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= diff --git a/cmn/common.go b/cmn/common.go index dd0823f11f6..1e71223f281 100644 --- a/cmn/common.go +++ b/cmn/common.go @@ -7,12 +7,10 @@ package cmn import ( "fmt" - "path/filepath" "strings" "time" "github.com/NVIDIA/aistore/api/apc" - "github.com/NVIDIA/aistore/cmn/debug" ) const GitHubHome = "https://github.com/NVIDIA/aistore" @@ -64,36 +62,3 @@ func PropToHeader(prop string) string { prop = strings.ReplaceAll(prop, "_", "-") return apc.HeaderPrefix + prop } - -// TODO -- FIXME: reconcile w/ PUT -func PromotedObjDstName(objfqn, dirfqn, givenObjName string) (objName string, err error) { - var baseName string - if strings.Contains(givenObjName, "../") { - return "", fmt.Errorf("invalid object name %q", givenObjName) - } - givenObjName = strings.TrimRightFunc(givenObjName, func(r rune) bool { - return r == filepath.Separator - }) - // first, base name - if dirfqn == "" { - // dst = "given-name/(fqn base)" unless the given name itself - // is a dir/name - if strings.ContainsRune(givenObjName, filepath.Separator) { - return givenObjName, nil - } - baseName = filepath.Base(objfqn) - } else { - baseName, err = filepath.Rel(dirfqn, objfqn) - debug.AssertNoErr(err) - if err != nil { - return - } - } - // destination name - if givenObjName == "" { - objName = baseName - } else { - objName = filepath.Join(givenObjName, baseName) - } - return -} diff --git a/xact/xs/dpromote.go b/xact/xs/dpromote.go index 12943461922..82e71d13b49 100644 --- a/xact/xs/dpromote.go +++ b/xact/xs/dpromote.go @@ -6,7 +6,9 @@ package xs import ( + "fmt" "path/filepath" + "strings" "sync" "github.com/NVIDIA/aistore/api/apc" @@ -103,7 +105,7 @@ func (r *XactDirPromote) walk(fqn string, de fs.DirEntry) error { // promote args := r.p.args - objName, err := cmn.PromotedObjDstName(fqn, args.SrcFQN, args.ObjName) + objName, err := PrmObjName(fqn, args.SrcFQN, args.ObjName) if err != nil { return err } @@ -146,3 +148,35 @@ func (r *XactDirPromote) Snap() (snap *cluster.Snap) { snap.IdleX = r.IsIdle() return } + +// +// naming +// + +func PrmObjName(objfqn, dirfqn, prefix string) (objName string, err error) { + if strings.Contains(prefix, "../") { + return "", fmt.Errorf("invalid object name or prefix %q", prefix) + } + if prefix != "" && cos.IsLastB(prefix, filepath.Separator) { + prefix = prefix[:len(prefix)-1] + } + var baseName string + if dirfqn == "" { + if strings.IndexByte(prefix, filepath.Separator) > 0 { + return prefix, nil + } + baseName = filepath.Base(objfqn) + } else { + baseName, err = filepath.Rel(dirfqn, objfqn) + if err != nil { + debug.Assert(false, err, dirfqn, objfqn) + return + } + } + if prefix == "" { + objName = baseName + } else { + objName = filepath.Join(prefix, baseName) + } + return +}