A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/orgrim/pg_back/commit/f6bbb1f55ba700707c35e482475dbe1c89eb1129 below:

fix sftp upload on windows by forcing the use of slashes in remote paths · orgrim/pg_back@f6bbb1f · GitHub

File tree Expand file treeCollapse file tree 1 file changed

+31

-5

lines changed

Filter options

Expand file treeCollapse file tree 1 file changed

+31

-5

lines changed Original file line number Diff line number Diff line change

@@ -453,9 +453,16 @@ func (r *sftpRepo) Upload(path string, target string) error {

453 453

defer src.Close()

454 454 455 455

rpath := filepath.Join(r.baseDir, target)

456 +

targetDir := filepath.Dir(rpath)

457 + 458 +

// sftp requires slash as path separator

459 +

if os.PathSeparator != '/' {

460 +

rpath = strings.ReplaceAll(rpath, string(os.PathSeparator), "/")

461 +

targetDir = strings.ReplaceAll(targetDir, string(os.PathSeparator), "/")

462 +

}

463 +

l.Verboseln("sftp remote path is:", rpath)

456 464 457 465

// Target directory must be created first

458 -

targetDir := filepath.Dir(rpath)

459 466

if targetDir != "." && targetDir != "/" {

460 467

if err := r.client.MkdirAll(targetDir); err != nil {

461 468

return fmt.Errorf("sftp: could not create parent directory of %s: %w", rpath, err)

@@ -469,23 +476,35 @@ func (r *sftpRepo) Upload(path string, target string) error {

469 476

defer dst.Close()

470 477 471 478

if _, err := io.Copy(dst, src); err != nil {

472 -

return fmt.Errorf("sftp: could not open send data with sftp: %s", err)

479 +

return fmt.Errorf("sftp: could not send data with sftp: %s", err)

473 480

}

474 481 475 482

return nil

476 483

}

477 484 478 485

func (r *sftpRepo) List(prefix string) (items []Item, rerr error) {

479 486

items = make([]Item, 0)

480 -

w := r.client.Walk(r.baseDir)

487 + 488 +

// sftp requires slash as path separator

489 +

baseDir := r.baseDir

490 +

if os.PathSeparator != '/' {

491 +

baseDir = strings.ReplaceAll(baseDir, string(os.PathSeparator), "/")

492 +

}

493 + 494 +

w := r.client.Walk(baseDir)

481 495

for w.Step() {

482 496

if err := w.Err(); err != nil {

483 497

l.Warnln("could not list remote file:", err)

484 498

rerr = err

485 499

continue

486 500

}

487 501 488 -

path := relPath(r.baseDir, w.Path())

502 +

// relPath() makes use of functions of the filepath std module

503 +

// that take care of putting back the proper os.PathSeparator

504 +

// if it find some slashes, so we can compare paths without

505 +

// worrying about path separators

506 +

path := relPath(baseDir, w.Path())

507 + 489 508

if !strings.HasPrefix(path, prefix) {

490 509

continue

491 510

}

@@ -502,7 +521,14 @@ func (r *sftpRepo) List(prefix string) (items []Item, rerr error) {

502 521

}

503 522 504 523

func (r *sftpRepo) Remove(path string) error {

505 -

if err := r.client.Remove(filepath.Join(r.baseDir, path)); err != nil {

524 +

rpath := filepath.Join(r.baseDir, path)

525 + 526 +

// sftp requires slash as path separator

527 +

if os.PathSeparator != '/' {

528 +

rpath = strings.ReplaceAll(rpath, string(os.PathSeparator), "/")

529 +

}

530 + 531 +

if err := r.client.Remove(rpath); err != nil {

506 532

return err

507 533

}

508 534

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4