copyRelativeDir copies all files from a relative directory (in the project) to the remote host.
(ctx context.Context, pj project.Project, relPath string, conn connector.Connector)
| 256 | |
| 257 | // copyRelativeDir copies all files from a relative directory (in the project) to the remote host. |
| 258 | func (ca copyArgs) copyRelativeDir(ctx context.Context, pj project.Project, relPath string, conn connector.Connector) (resRrr error) { |
| 259 | defer func() { |
| 260 | resRrr = ca.ensureDestDirMode(ctx, conn) |
| 261 | }() |
| 262 | return pj.WalkDir(relPath, func(path string, d fs.DirEntry, err error) error { |
| 263 | if err != nil { |
| 264 | return err |
| 265 | } |
| 266 | // Only copy files, skip directories |
| 267 | if d.IsDir() { |
| 268 | return nil |
| 269 | } |
| 270 | |
| 271 | info, err := d.Info() |
| 272 | if err != nil { |
| 273 | return errors.Wrap(err, "failed to get file info") |
| 274 | } |
| 275 | |
| 276 | mode := info.Mode() |
| 277 | |
| 278 | data, err := pj.ReadFile(path) |
| 279 | if err != nil { |
| 280 | return errors.Wrap(err, "failed to read file") |
| 281 | } |
| 282 | |
| 283 | rel, err := pj.Rel(relPath, path) |
| 284 | if err != nil { |
| 285 | return errors.Wrap(err, "failed to get relative file path") |
| 286 | } |
| 287 | dest := filepath.Join(ca.dest, rel) |
| 288 | |
| 289 | return connector.PutData(ctx, data, dest, mode, conn) |
| 290 | }) |
| 291 | } |
| 292 | |
| 293 | // ensureDestDirMode if mode args exists, ensure dest dir mode after all files copied |
| 294 | func (ca copyArgs) ensureDestDirMode(ctx context.Context, conn connector.Connector) error { |
no test coverage detected