mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-06-27 03:11:46 +00:00
Add option to control compression modes
This commit is contained in:
parent
84c680266a
commit
346a651a48
4 changed files with 22 additions and 6 deletions
|
|
@ -26,6 +26,14 @@ receiving computer. In :code:`normal` mode the last argument is assumed to be a
|
|||
destination path on the receiving computer.
|
||||
|
||||
|
||||
--compress
|
||||
default=auto
|
||||
choices=auto,never,always
|
||||
Whether to compress data being sent. By default compression is enabled based on the
|
||||
type of file being sent. For files recognized as being already compressed, compression
|
||||
is turned off as it just wastes CPU cycles.
|
||||
|
||||
|
||||
--permissions-bypass -p
|
||||
The password to use to skip the transfer confirmation popup in kitty. Must match
|
||||
the password set for the :opt:`file_transfer_confirmation_bypass` option in
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ func get_remote_path(local_path string, remote_base string) string {
|
|||
return remote_base
|
||||
}
|
||||
|
||||
func NewFile(local_path, expanded_local_path string, file_id int, stat_result fs.FileInfo, remote_base string, file_type FileType) *File {
|
||||
func NewFile(opts *Options, local_path, expanded_local_path string, file_id int, stat_result fs.FileInfo, remote_base string, file_type FileType) *File {
|
||||
stat, ok := stat_result.Sys().(*syscall.Stat_t)
|
||||
if !ok {
|
||||
panic("This platform does not support getting file identities from stat results")
|
||||
|
|
@ -129,7 +129,7 @@ func NewFile(local_path, expanded_local_path string, file_id int, stat_result fs
|
|||
file_size: stat_result.Size(), bytes_to_transmit: stat_result.Size(),
|
||||
permissions: stat_result.Mode().Perm(), remote_path: filepath.ToSlash(get_remote_path(local_path, remote_base)),
|
||||
rsync_capable: file_type == FileType_regular && stat_result.Size() > 4096,
|
||||
compression_capable: file_type == FileType_regular && stat_result.Size() > 4096 && should_be_compressed(expanded_local_path),
|
||||
compression_capable: file_type == FileType_regular && stat_result.Size() > 4096 && should_be_compressed(expanded_local_path, opts.Compress),
|
||||
remote_initial_size: -1,
|
||||
}
|
||||
return &ans
|
||||
|
|
@ -144,7 +144,7 @@ func process(opts *Options, paths []string, remote_base string, counter *int) (a
|
|||
}
|
||||
if s.IsDir() {
|
||||
*counter += 1
|
||||
ans = append(ans, NewFile(x, expanded, *counter, s, remote_base, FileType_directory))
|
||||
ans = append(ans, NewFile(opts, x, expanded, *counter, s, remote_base, FileType_directory))
|
||||
new_remote_base := remote_base
|
||||
if new_remote_base != "" {
|
||||
new_remote_base = strings.TrimRight(new_remote_base, "/") + "/" + filepath.Base(x) + "/"
|
||||
|
|
@ -166,10 +166,10 @@ func process(opts *Options, paths []string, remote_base string, counter *int) (a
|
|||
ans = append(ans, new_ans...)
|
||||
} else if s.Mode()&fs.ModeSymlink == fs.ModeSymlink {
|
||||
*counter += 1
|
||||
ans = append(ans, NewFile(x, expanded, *counter, s, remote_base, FileType_symlink))
|
||||
ans = append(ans, NewFile(opts, x, expanded, *counter, s, remote_base, FileType_symlink))
|
||||
} else if s.Mode().IsRegular() {
|
||||
*counter += 1
|
||||
ans = append(ans, NewFile(x, expanded, *counter, s, remote_base, FileType_regular))
|
||||
ans = append(ans, NewFile(opts, x, expanded, *counter, s, remote_base, FileType_regular))
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
|
|||
|
|
@ -84,7 +84,13 @@ func run_with_paths(cwd, home string, f func()) {
|
|||
f()
|
||||
}
|
||||
|
||||
func should_be_compressed(path string) bool {
|
||||
func should_be_compressed(path, strategy string) bool {
|
||||
if strategy == "always" {
|
||||
return true
|
||||
}
|
||||
if strategy == "never" {
|
||||
return false
|
||||
}
|
||||
ext := strings.ToLower(filepath.Ext(path))
|
||||
if ext != "" {
|
||||
switch ext[1:] {
|
||||
|
|
|
|||
|
|
@ -508,3 +508,5 @@ class TestFileTransmission(BaseTest):
|
|||
single_file('--transmit-deltas')
|
||||
os.remove(dest)
|
||||
single_file('--transmit-deltas')
|
||||
single_file('--compress=never')
|
||||
single_file('--compress=always')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue