Skip to content

Commit b4e9183

Browse files
committed
Add an example for gio::Vfs implementation
Signed-off-by: fbrouille <fbrouille@users.noreply.github.com>
1 parent 1ff2d05 commit b4e9183

File tree

8 files changed

+1040
-6
lines changed

8 files changed

+1040
-6
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ path = "object_subclass/main.rs"
5151
[[bin]]
5252
name = "virtual_methods"
5353
path = "virtual_methods/main.rs"
54+
55+
[lib]
56+
name = "gio_vfs"
57+
path = "gio_vfs/lib.rs"
58+
crate-type = ["cdylib"]

examples/gio_vfs/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# GIO VFS
2+
3+
This example demonstrates the usage of GIO VFS. Built artifact is a dynamic system library that is used as a GIO module
4+
(see https://docs.gtk.org/gio/overview.html#running-gio-applications)
5+
6+
Build, install and configure it by executing:
7+
```bash
8+
cargo build -p gtk-rs-examples --lib
9+
export GIO_EXTRA_MODULES=/tmp/gio_modules
10+
mkdir -p $GIO_EXTRA_MODULES && cp ./target/debug/libgio_vfs.so $GIO_EXTRA_MODULES
11+
export MYVFS_ROOT=/tmp/myvfs
12+
mkdir -p $MYVFS_ROOT
13+
```
14+
15+
`GIO_EXTRA_MODULES` specify additional directories for `gio` command line tool to automatically load modules.
16+
17+
`MYVFS_ROOT` specify the local directory that is used by as backend directory for uri starting with `myvfs:///` (e.g. if `MYVFS_ROOT-/tmp` `myvfs:///foo` points to `/tmp/foo`).
18+
19+
`gio` command line tool automatically loads this extra module that implement all file commands for files with uri starting with `myvfs:///`
20+
21+
Run it by executing the following commands:
22+
23+
Basic operations:
24+
```bash
25+
echo "foo" | gio save myvfs:///foo
26+
gio cat myvfs:///foo
27+
gio set -t string myvfs:///foo xattr::my_string value
28+
gio info myvfs:///foo
29+
gio mkdir myvfs:///bar
30+
gio copy myvfs:///foo myvfs:///bar/
31+
gio list myvfs:///
32+
gio tree myvfs:///
33+
gio move -b myvfs:///bar/foo myvfs:///foo
34+
gio tree myvfs:///
35+
gio remove myvfs:///foo myvfs:///foo~ myvfs:///bar
36+
gio list myvfs:///
37+
```
38+
39+
Monitor `myvfs:///`:
40+
```bash
41+
# monitor is a blocking operation. kill it with Ctrl+C
42+
gio monitor myvfs:///
43+
```
44+
45+
```bash
46+
# in another terminal (ensure MYVFS_ROOT is defined)
47+
touch $MYVFS_ROOT/foo
48+
echo "foo" > $MYVFS_ROOT/foo
49+
mkdir $MYVFS_ROOT/bar
50+
cp $MYVFS_ROOT/foo $MYVFS_ROOT/foo2
51+
mv -b $MYVFS_ROOT/foo2 $MYVFS_ROOT/foo
52+
rm -rf $MYVFS_ROOT/*
53+
```

0 commit comments

Comments
 (0)