| author | wenzelm |
| Sat, 08 Apr 2023 20:21:30 +0200 | |
| changeset 77795 | 4c4bd44ff683 |
| parent 77793 | 6d03e2114ec5 |
| child 77852 | df35b5b7b6a4 |
| permissions | -rw-r--r-- |
| 75523 | 1 |
/* Title: Pure/General/rsync.scala |
2 |
Author: Makarius |
|
3 |
||
| 77793 | 4 |
Support for rsync, based on Isabelle component. |
| 75523 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
object Rsync {
|
|
| 77787 | 11 |
object Context {
|
12 |
def apply( |
|
13 |
progress: Progress = new Progress, |
|
14 |
ssh: SSH.System = SSH.Local, |
|
| 77795 | 15 |
archive: Boolean = true, |
16 |
stats: Boolean = true |
|
|
77788
c2ce9ac85859
use remote copy of locally installed rsync component: for uniform version and options;
wenzelm
parents:
77787
diff
changeset
|
17 |
): Context = {
|
|
c2ce9ac85859
use remote copy of locally installed rsync component: for uniform version and options;
wenzelm
parents:
77787
diff
changeset
|
18 |
val directory = Components.provide(Component_Rsync.home, ssh = ssh, progress = progress) |
| 77795 | 19 |
new Context(directory, progress, archive, stats) |
|
77788
c2ce9ac85859
use remote copy of locally installed rsync component: for uniform version and options;
wenzelm
parents:
77787
diff
changeset
|
20 |
} |
| 77787 | 21 |
} |
22 |
||
23 |
final class Context private( |
|
| 77790 | 24 |
directory: Components.Directory, |
| 77787 | 25 |
val progress: Progress, |
26 |
archive: Boolean, |
|
| 77795 | 27 |
stats: Boolean |
| 75527 | 28 |
) {
|
| 77791 | 29 |
override def toString: String = directory.toString |
30 |
||
| 77795 | 31 |
def no_progress: Context = new Context(directory, new Progress, archive, stats) |
32 |
def no_archive: Context = new Context(directory, progress, false, stats) |
|
| 77790 | 33 |
|
34 |
def ssh: SSH.System = directory.ssh |
|
| 77787 | 35 |
|
|
76136
1bb677cceea4
let rsync re-use ssh connection via control path;
wenzelm
parents:
76131
diff
changeset
|
36 |
def command: String = {
|
| 77790 | 37 |
val program = Component_Rsync.remote_program(directory) |
|
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
38 |
val ssh_command = ssh.client_command |
|
77792
b81b2c50fc7c
use "rsync --secluded-args" by default, discontinue obsolete option -P of sync tools;
wenzelm
parents:
77791
diff
changeset
|
39 |
File.bash_path(Component_Rsync.local_program) + " --secluded-args" + |
|
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
40 |
if_proper(ssh_command, " --rsh=" + Bash.string(ssh_command)) + |
| 77790 | 41 |
" --rsync-path=" + Bash.string(quote(File.standard_path(program))) + |
| 77795 | 42 |
(if (archive) " --archive" else "") + |
43 |
(if (stats) " --stats" else "") |
|
|
76136
1bb677cceea4
let rsync re-use ssh connection via control path;
wenzelm
parents:
76131
diff
changeset
|
44 |
} |
|
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
45 |
|
|
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
46 |
def target(path: Path, direct: Boolean = false): String = {
|
|
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
47 |
val s = ssh.rsync_path(path) |
|
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
48 |
if (direct) Url.direct_path(s) else s |
|
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
49 |
} |
|
75525
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
50 |
} |
|
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
51 |
|
| 75526 | 52 |
def exec( |
|
75525
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
53 |
context: Context, |
| 75523 | 54 |
thorough: Boolean = false, |
55 |
prune_empty_dirs: Boolean = false, |
|
56 |
dry_run: Boolean = false, |
|
57 |
clean: Boolean = false, |
|
58 |
filter: List[String] = Nil, |
|
59 |
args: List[String] = Nil |
|
60 |
): Process_Result = {
|
|
| 77517 | 61 |
val progress = context.progress |
| 75523 | 62 |
val script = |
|
75525
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
63 |
context.command + |
|
77518
fda4da0f80f4
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77517
diff
changeset
|
64 |
(if (progress.verbose) " --verbose" else "") + |
| 75523 | 65 |
(if (thorough) " --ignore-times" else " --omit-dir-times") + |
66 |
(if (prune_empty_dirs) " --prune-empty-dirs" else "") + |
|
67 |
(if (dry_run) " --dry-run" else "") + |
|
68 |
(if (clean) " --delete-excluded" else "") + |
|
69 |
filter.map(s => " --filter=" + Bash.string(s)).mkString + |
|
| 77369 | 70 |
if_proper(args, " " + Bash.strings(args)) |
| 77517 | 71 |
progress.bash(script, echo = true) |
| 75523 | 72 |
} |
73 |
||
|
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
74 |
def init(context: Context, target: Path, |
| 75523 | 75 |
contents: List[File.Content] = Nil |
76 |
): Unit = |
|
77 |
Isabelle_System.with_tmp_dir("sync") { tmp_dir =>
|
|
78 |
val init_dir = Isabelle_System.make_directory(tmp_dir + Path.explode("init"))
|
|
79 |
contents.foreach(_.write(init_dir)) |
|
| 77787 | 80 |
exec(context.no_archive, |
|
75534
1d937b12204d
more robust: no change of directory attributes of initial test, notably target without .hg_sync meta data;
wenzelm
parents:
75527
diff
changeset
|
81 |
thorough = true, |
|
1d937b12204d
more robust: no change of directory attributes of initial test, notably target without .hg_sync meta data;
wenzelm
parents:
75527
diff
changeset
|
82 |
args = |
|
1d937b12204d
more robust: no change of directory attributes of initial test, notably target without .hg_sync meta data;
wenzelm
parents:
75527
diff
changeset
|
83 |
List(if (contents.nonEmpty) "--archive" else "--dirs", |
|
77783
fb61887c069a
clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents:
77518
diff
changeset
|
84 |
File.bash_path(init_dir) + "/.", context.target(target))).check |
| 75523 | 85 |
} |
86 |
} |