remoteCopyFileInternal copies FROM local (this host) TO local (this host) Only supports copying files, not directories
(srcUri, destUri string, srcPathCleaned, destPathCleaned string, destHasSlash bool, overwrite bool)
| 73 | // remoteCopyFileInternal copies FROM local (this host) TO local (this host) |
| 74 | // Only supports copying files, not directories |
| 75 | func remoteCopyFileInternal(srcUri, destUri string, srcPathCleaned, destPathCleaned string, destHasSlash bool, overwrite bool) error { |
| 76 | srcFileStat, err := os.Stat(srcPathCleaned) |
| 77 | if err != nil { |
| 78 | return fmt.Errorf("cannot stat file %q: %w", srcPathCleaned, err) |
| 79 | } |
| 80 | if srcFileStat.IsDir() { |
| 81 | return fmt.Errorf("copying directories is not supported") |
| 82 | } |
| 83 | if srcFileStat.Size() > RemoteFileTransferSizeLimit { |
| 84 | return fmt.Errorf("file %q size %d exceeds transfer limit of %d bytes", srcPathCleaned, srcFileStat.Size(), RemoteFileTransferSizeLimit) |
| 85 | } |
| 86 | |
| 87 | destFilePath, err := prepareDestForCopy(destPathCleaned, filepath.Base(srcPathCleaned), destHasSlash, overwrite) |
| 88 | if err != nil { |
| 89 | return err |
| 90 | } |
| 91 | |
| 92 | srcFile, err := os.Open(srcPathCleaned) |
| 93 | if err != nil { |
| 94 | return fmt.Errorf("cannot open file %q: %w", srcPathCleaned, err) |
| 95 | } |
| 96 | defer srcFile.Close() |
| 97 | |
| 98 | destFile, err := os.OpenFile(destFilePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, srcFileStat.Mode()) |
| 99 | if err != nil { |
| 100 | return fmt.Errorf("cannot create file %q: %w", destFilePath, err) |
| 101 | } |
| 102 | defer destFile.Close() |
| 103 | |
| 104 | if _, err = io.Copy(destFile, srcFile); err != nil { |
| 105 | return fmt.Errorf("cannot copy %q to %q: %w", srcUri, destUri, err) |
| 106 | } |
| 107 | return nil |
| 108 | } |
| 109 | |
| 110 | // RemoteFileCopyCommand copies a file FROM somewhere TO here |
| 111 | func (impl *ServerImpl) RemoteFileCopyCommand(ctx context.Context, data wshrpc.CommandFileCopyData) (bool, error) { |
no test coverage detected