Skip to content

Commit 794a373

Browse files
authored
Merge pull request #54 from eXistSolutions/file-sync-3
[enhancement] add article for file:sync#3
2 parents 2562d6a + 5879410 commit 794a373

File tree

1 file changed

+68
-0
lines changed
  • src/main/xar-resources/data/docs/file

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
`file:sync#3` will write the contents of the target collection to the target directory on the file system.
2+
This will include the entire tree (subcollections and their contents).
3+
4+
Since eXist-DB 5.4.0 the third parameter can now be of type xs:dateTime (kept for backwards compatibility)
5+
or a map of options.
6+
7+
## Options Map
8+
9+
The map has three keys at the moment:
10+
11+
- `after`: xs:dateTime? default `()`
12+
- synchronise only files newer than the dateTime provided
13+
- this behaves exactly as providing the xs:dateTime before
14+
- not setting this option will synchronize all files and collections
15+
- `prune`: xs:boolean default `()`
16+
- flag to control if surplus files on the filesystem should be removed
17+
- `exclude`: xs:string* default `()`
18+
- a sequence of glob patterns
19+
- patterns support globs like `*`, `?` and `**` placeholders
20+
- files that match any of the patterns will __not__ be removed from disk
21+
22+
Whenever file:sync selects a file or folder for deletion it will report this in the returned file:sync element.
23+
24+
__NOTE:__ This function returns a `document-node()`.
25+
26+
## Examples Using Options Map
27+
28+
### Sync to a git repository
29+
30+
Say, you want to synchronize the state of a collection to the a working directory of a git-repository.
31+
While it is useful to also remove files that are not in the database collection of you application you
32+
still will want to preserve `.git`, `.gitignore` and maybe other dotfiles like `.env`. The following
33+
example shows how to do that.
34+
35+
```xquery
36+
file:sync("/db/apps/my-app", "/Users/me/projects/my-app", map {
37+
"prune": true(), (: remove anything not in the database :)
38+
"excludes": (".*") (: do not remove dotfiles, this will leave .git folder and .gitignore untouched :)
39+
})
40+
```
41+
42+
Before v5.4.0 the above required multiple calls to `process:execute#2` and some command line trickery.
43+
44+
### Example report with deletions
45+
46+
```xml
47+
<file:sync xmlns:file="http://exist-db.org/xquery/file" collection="/db/apps/my-app" dir="/Users/me/projects/my-app">
48+
<file:delete file="/Users/me/projects/my-app/extra.file" name="extra.file"/>
49+
</file:sync>
50+
```
51+
52+
## Synchronize changes made in the last day
53+
54+
### Example Using Options Map
55+
56+
```xquery
57+
file:sync("/db/apps/my-app", "/Users/me/projects/my-app", map {
58+
"after": current-dateTime() - xs:dayTimeDuration("PT1D"), (: changes in the last day :)
59+
})
60+
```
61+
62+
### Example Using Deprecated xs:dateTime
63+
64+
```xquery
65+
file:sync("/db/apps/my-app", "/Users/me/projects/my-app",
66+
current-dateTime() - xs:dayTimeDuration("PT1D") (: changes in the last day :)
67+
)
68+
```

0 commit comments

Comments
 (0)