@@ -28,7 +28,7 @@ func GetParentPath(conn *connparse.Connection) string {
28
28
29
29
func GetParentPathString (hostAndPath string ) string {
30
30
if hostAndPath == "" || hostAndPath == fspath .Separator {
31
- return fspath . Separator
31
+ return ""
32
32
}
33
33
34
34
// Remove trailing slash if present
@@ -38,24 +38,9 @@ func GetParentPathString(hostAndPath string) string {
38
38
39
39
lastSlash := strings .LastIndex (hostAndPath , fspath .Separator )
40
40
if lastSlash <= 0 {
41
- return fspath .Separator
42
- }
43
- return hostAndPath [:lastSlash + 1 ]
44
- }
45
-
46
- const minURILength = 10 // Minimum length for a valid URI (e.g., "s3://bucket")
47
-
48
- func GetPathPrefix (conn * connparse.Connection ) string {
49
- fullUri := conn .GetFullURI ()
50
- if fullUri == "" {
51
41
return ""
52
42
}
53
- pathPrefix := fullUri
54
- lastSlash := strings .LastIndex (fullUri , fspath .Separator )
55
- if lastSlash > minURILength && lastSlash < len (fullUri )- 1 {
56
- pathPrefix = fullUri [:lastSlash + 1 ]
57
- }
58
- return pathPrefix
43
+ return hostAndPath [:lastSlash + 1 ]
59
44
}
60
45
61
46
func PrefixCopyInternal (ctx context.Context , srcConn , destConn * connparse.Connection , c fstype.FileShareClient , opts * wshrpc.FileCopyOpts , listEntriesPrefix func (ctx context.Context , host string , path string ) ([]string , error ), copyFunc func (ctx context.Context , host string , path string ) error ) (bool , error ) {
@@ -102,12 +87,18 @@ func PrefixCopyInternal(ctx context.Context, srcConn, destConn *connparse.Connec
102
87
}
103
88
104
89
func PrefixCopyRemote (ctx context.Context , srcConn , destConn * connparse.Connection , srcClient , destClient fstype.FileShareClient , destPutFile func (host string , path string , size int64 , reader io.Reader ) error , opts * wshrpc.FileCopyOpts ) (bool , error ) {
90
+ // prefix to be used if the destination is a directory. The destPath returned in the following call only applies if the destination is not a directory.
91
+ destPathPrefix , err := CleanPathPrefix (destConn .Path )
92
+ if err != nil {
93
+ return false , fmt .Errorf ("error cleaning destination path: %w" , err )
94
+ }
95
+ destPathPrefix += fspath .Separator
96
+
105
97
_ , destPath , srcInfo , err := DetermineCopyDestPath (ctx , srcConn , destConn , srcClient , destClient , opts )
106
98
if err != nil {
107
- if ! errors .Is (err , fs .ErrNotExist ) {
108
- return false , err
109
- }
99
+ return false , err
110
100
}
101
+
111
102
log .Printf ("Copying: %v -> %v" , srcConn .GetFullURI (), destConn .GetFullURI ())
112
103
readCtx , cancel := context .WithCancelCause (ctx )
113
104
defer cancel (nil )
@@ -119,7 +110,7 @@ func PrefixCopyRemote(ctx context.Context, srcConn, destConn *connparse.Connecti
119
110
if singleFile && srcInfo .IsDir {
120
111
return fmt .Errorf ("protocol error: source is a directory, but only a single file is being copied" )
121
112
}
122
- fileName , err := CleanPathPrefix (fspath .Join (destPath , next .Name ))
113
+ fileName , err := CleanPathPrefix (fspath .Join (destPathPrefix , next .Name ))
123
114
if singleFile {
124
115
fileName = destPath
125
116
}
@@ -144,10 +135,7 @@ func DetermineCopyDestPath(ctx context.Context, srcConn, destConn *connparse.Con
144
135
}
145
136
146
137
srcHasSlash := strings .HasSuffix (srcConn .Path , fspath .Separator )
147
- srcPath , err = CleanPathPrefix (srcConn .Path )
148
- if err != nil {
149
- return "" , "" , nil , fmt .Errorf ("error cleaning source path: %w" , err )
150
- }
138
+ srcPath = srcConn .Path
151
139
destHasSlash := strings .HasSuffix (destConn .Path , fspath .Separator )
152
140
destPath , err = CleanPathPrefix (destConn .Path )
153
141
if err != nil {
@@ -179,7 +167,7 @@ func DetermineCopyDestPath(ctx context.Context, srcConn, destConn *connparse.Con
179
167
}
180
168
if destExists {
181
169
if overwrite {
182
- err = destClient .Delete (ctx , destConn , true )
170
+ err = destClient .Delete (ctx , destConn , destInfo . IsDir )
183
171
if err != nil {
184
172
return "" , "" , nil , fmt .Errorf ("error deleting conflicting destination file: %w" , err )
185
173
}
@@ -197,7 +185,7 @@ func DetermineCopyDestPath(ctx context.Context, srcConn, destConn *connparse.Con
197
185
// CleanPathPrefix corrects paths for prefix filesystems (i.e. ones that don't have directories)
198
186
func CleanPathPrefix (path string ) (string , error ) {
199
187
if path == "" {
200
- return "" , fmt . Errorf ( "path is empty" )
188
+ return "" , nil
201
189
}
202
190
if strings .HasPrefix (path , fspath .Separator ) {
203
191
path = path [1 :]
0 commit comments