| author | wenzelm |
| Tue, 07 Jun 2022 17:07:10 +0200 | |
| changeset 75525 | 68162e4f60a7 |
| parent 75524 | ff8012edac89 |
| child 75526 | 57b6a28e4eba |
| permissions | -rw-r--r-- |
| 75523 | 1 |
/* Title: Pure/General/rsync.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Support for rsync: see also https://rsync.samba.org |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
object Rsync {
|
|
|
75525
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
11 |
sealed case class Context(progress: Progress, port: Int = SSH.default_port) {
|
|
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
12 |
def command: String = |
|
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
13 |
"rsync --protect-args --archive --rsh=" + Bash.string("ssh -p " + port)
|
|
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
14 |
} |
|
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
15 |
|
| 75523 | 16 |
def rsync( |
|
75525
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
17 |
context: Context, |
| 75523 | 18 |
verbose: Boolean = false, |
19 |
thorough: Boolean = false, |
|
20 |
prune_empty_dirs: Boolean = false, |
|
21 |
dry_run: Boolean = false, |
|
22 |
clean: Boolean = false, |
|
23 |
list: Boolean = false, |
|
24 |
filter: List[String] = Nil, |
|
25 |
args: List[String] = Nil |
|
26 |
): Process_Result = {
|
|
27 |
val script = |
|
|
75525
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
28 |
context.command + |
| 75523 | 29 |
(if (verbose) " --verbose" else "") + |
30 |
(if (thorough) " --ignore-times" else " --omit-dir-times") + |
|
31 |
(if (prune_empty_dirs) " --prune-empty-dirs" else "") + |
|
32 |
(if (dry_run) " --dry-run" else "") + |
|
33 |
(if (clean) " --delete-excluded" else "") + |
|
34 |
(if (list) " --list-only --no-human-readable" else "") + |
|
35 |
filter.map(s => " --filter=" + Bash.string(s)).mkString + |
|
36 |
(if (args.nonEmpty) " " + Bash.strings(args) else "") |
|
|
75525
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
37 |
context.progress.bash(script, echo = true) |
| 75523 | 38 |
} |
39 |
||
|
75525
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
40 |
def rsync_init(context: Context, target: String, |
| 75523 | 41 |
contents: List[File.Content] = Nil |
42 |
): Unit = |
|
43 |
Isabelle_System.with_tmp_dir("sync") { tmp_dir =>
|
|
44 |
val init_dir = Isabelle_System.make_directory(tmp_dir + Path.explode("init"))
|
|
45 |
contents.foreach(_.write(init_dir)) |
|
|
75525
68162e4f60a7
clarified signature: more explicit type Rsync.Context;
wenzelm
parents:
75524
diff
changeset
|
46 |
rsync(context, thorough = true, |
| 75523 | 47 |
args = List(File.bash_path(init_dir) + "/.", target)).check |
48 |
} |
|
| 75524 | 49 |
|
50 |
def terminate(target: String): String = |
|
51 |
if (target.endsWith(":") || target.endsWith("/")) target + "."
|
|
52 |
else if (target.endsWith(":.") || target.endsWith("/.")) target
|
|
53 |
else target + "/." |
|
54 |
||
55 |
def append(target: String, rest: String): String = |
|
56 |
if (target.endsWith(":") || target.endsWith("/")) target + rest
|
|
57 |
else target + "/" + rest |
|
| 75523 | 58 |
} |