Skip to content

Commit 10bb6d0

Browse files
committed
Add an example for gio::Vfs implementation
Signed-off-by: fbrouille <[email protected]>
1 parent 5fbbb09 commit 10bb6d0

File tree

8 files changed

+1042
-8
lines changed

8 files changed

+1042
-8
lines changed

Cargo.lock

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

0 commit comments

Comments
 (0)