Skip to content

Commit

Permalink
follow up
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Dec 7, 2023
1 parent 2f4dc87 commit a628085
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 41 deletions.
4 changes: 2 additions & 2 deletions ais/tgttxn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
35 changes: 0 additions & 35 deletions cmn/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
36 changes: 35 additions & 1 deletion xact/xs/dpromote.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
package xs

import (
"fmt"
"path/filepath"
"strings"
"sync"

"github.com/NVIDIA/aistore/api/apc"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

0 comments on commit a628085

Please sign in to comment.