Use correct target path during mirroring objects (#4807)
Currently if we don't use absolute paths in mirror command, absolute path of
source gets appended to the target path and so in destination object gets
mirrored to wrong prefix / path.
For example say source object path is `/tmp/source/prefix/a.txt` and mirror
command executed from `/tmp` dir as `mc mirror --json --watch source xyz`,
the object in target gets mirrored to location `xyz/tmp/source/prefix/a.txt`.
Also any new file created gets copied properly though.
```
mc mirror --json --watch source/ xyz/
{
"status": "success",
"source": "/tmp/source/prefix/a.txt",
"target": "xyz/tmp/source/prefix/a.txt",
"size": 0,
"totalCount": 1,
"totalSize": 0
}
{
"status": "success",
"source": "/tmp/source/b.txt",
"target": "xyz/b.txt",
"size": 0,
"totalCount": 2,
"totalSize": 0
}
```
With the fix now after running the command `mc mirror --json --watch source xyz`
the object would correctly get copied to location `/tmp/xyz/prefix/a.txt` as below
```
{
"status": "success",
"source": "/tmp/source/prefix/a.txt",
"target": "xyz/prefix/a.txt",
"size": 0,
"totalCount": 2,
"totalSize": 0
}
{
"status": "success",
"source": "/tmp/source/b.txt",
"target": "xyz/b.txt",
"size": 0,
"totalCount": 1,
"totalSize": 0
}
{
"status": "success",
"source": "/tmp/source/c.txt",
"target": "xyz/c.txt",
"size": 0,
"totalCount": 3,
"totalSize": 0
}
```
Signed-off-by: Shubhendu Ram Tripathi <shubhendu@minio.io>
This commit is contained in:
@@ -127,6 +127,15 @@ func deltaSourceTarget(ctx context.Context, sourceURL, targetURL string, opts mi
|
||||
return
|
||||
}
|
||||
|
||||
// If the passed source URL points to fs, fetch the absolute src path
|
||||
// to correctly calculate targetPath
|
||||
if sourceAlias == "" {
|
||||
tmpSrcURL, e := filepath.Abs(sourceURL)
|
||||
if e == nil {
|
||||
sourceURL = tmpSrcURL
|
||||
}
|
||||
}
|
||||
|
||||
// List both source and target, compare and return values through channel.
|
||||
for diffMsg := range objectDifference(ctx, sourceClnt, targetClnt, opts.isMetadata) {
|
||||
if diffMsg.Error != nil {
|
||||
|
||||
Reference in New Issue
Block a user