1
1
mirror of https://github.com/mgree/ffs.git synced 2024-08-16 14:50:35 +03:00

change default behavior to modify newlines; update readme

This commit is contained in:
Michael Greenberg 2021-06-24 11:05:57 -04:00
parent a02d674ae5
commit 5a0100bfb1
8 changed files with 38 additions and 67 deletions

View File

@ -15,61 +15,31 @@ know.
Run `ffs [mountpoint] [file]` to mount a file at a given mountpoint. Run `ffs [mountpoint] [file]` to mount a file at a given mountpoint.
```shell-session ```shell-session
$ ffs mnt json_eg1.json & $ cat object.json
[1] 80762 { "name": "Michael Greenberg", "eyes": 2, "fingernails": 10, "human": true }
$ tree mnt $ ffs -o object_edited.json object.json &
mnt [1] 60182
└── glossary $ tree object
├── GlossDiv object
│   ├── GlossList ├── eyes
│   │   └── GlossEntry ├── fingernails
│   │   ├── Abbrev ├── human
│   │   ├── Acronym └── name
│   │   ├── GlossDef
│   │   │   ├── GlossSeeAlso
│   │   │   │   ├── 0
│   │   │   │   └── 1
│   │   │   └── para
│   │   ├── GlossSee
│   │   ├── GlossTerm
│   │   ├── ID
│   │   └── SortAs
│   └── title
└── title
6 directories, 11 files 0 directories, 4 files
$ cat mnt/glossary/GlossDiv/GlossList/GlossEntry/Abbrev $ echo Mikey Indiana >object/name
ISO 8879:1986$ cat mnt/glossary/GlossDiv/GlossList/GlossEntry/Acronym $ echo 1 >object/nose
SGML$ cat mnt/glossary/title $ mkdir object/pockets
example glossary$ cat json_eg1.json $ cd object/pockets/
{ $ echo keys >pants
"glossary": { $ echo pen >shirt
"title": "example glossary", $ cd ..
"GlossDiv": { $ cd ..
"title": "S", $ umount object
"GlossList": { $
"GlossEntry": { [1]+ Done ffs -o object_edited.json object.json
"ID": "SGML", $ cat object_edited.json
"SortAs": "SGML", {"eyes":2,"fingernails":10,"human":true,"name":"Mikey Indiana","nose":1,"pockets":{"pants":"keys","shirt":"pen"}}
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
$ ps | grep ffs
80762 ttys001 0:00.03 ffs mnt json_eg1.json
80843 ttys001 0:00.00 grep ffs
$ umount mnt
[1]+ Done ffs mnt json_eg1.json
$
``` ```
# External dependencies # External dependencies

View File

@ -81,7 +81,7 @@ impl Default for Config {
gid: 501, gid: 501,
filemode: 0o644, filemode: 0o644,
dirmode: 0o755, dirmode: 0o755,
add_newlines: false, add_newlines: true,
pad_element_names: true, pad_element_names: true,
base64: base64::STANDARD, base64: base64::STANDARD,
try_decode_base64: false, try_decode_base64: false,

View File

@ -299,6 +299,7 @@ where
if fs.config.add_newlines && contents.ends_with('\n') { if fs.config.add_newlines && contents.ends_with('\n') {
contents.truncate(contents.len() - 1); contents.truncate(contents.len() - 1);
} }
// TODO 2021-06-24 trim?
V::from_string(contents, &fs.config) V::from_string(contents, &fs.config)
} }
Err(_) => V::from_bytes(contents, &fs.config), Err(_) => V::from_bytes(contents, &fs.config),

View File

@ -62,9 +62,9 @@ fn main() {
.default_value("755") .default_value("755")
) )
.arg( .arg(
Arg::with_name("NEWLINE") Arg::with_name("EXACT")
.help("Add a newline to the end of values that don't already have them") .help("Don't add newlines to the end of values that don't already have them (or strip them when loading)")
.long("newline") .long("exact")
) )
.arg( .arg(
Arg::with_name("UNPADDED") Arg::with_name("UNPADDED")
@ -145,7 +145,7 @@ fn main() {
.init(); .init();
} }
config.add_newlines = args.is_present("NEWLINE"); config.add_newlines = !args.is_present("EXACT");
config.pad_element_names = !args.is_present("UNPADDED"); config.pad_element_names = !args.is_present("UNPADDED");
config.read_only = args.is_present("READONLY"); config.read_only = args.is_present("READONLY");
config.filemode = match u16::from_str_radix(args.value_of("FILEMODE").unwrap(), 8) { config.filemode = match u16::from_str_radix(args.value_of("FILEMODE").unwrap(), 8) {

View File

@ -22,7 +22,7 @@ printf "10" >"${EXP}/fingernails"
printf "true" >"${EXP}/human" printf "true" >"${EXP}/human"
printf "" >"${EXP}/problems" printf "" >"${EXP}/problems"
ffs -m "$MNT" ../json/object_null.json & ffs --exact -m "$MNT" ../json/object_null.json &
PID=$! PID=$!
sleep 2 sleep 2
cd "$MNT" cd "$MNT"

View File

@ -22,7 +22,7 @@ printf "10\n" >"${EXP}/fingernails"
printf "true\n" >"${EXP}/human" printf "true\n" >"${EXP}/human"
printf "" >"${EXP}/problems" printf "" >"${EXP}/problems"
ffs --newline -m "$MNT" ../json/object_null.json & ffs -m "$MNT" ../json/object_null.json &
PID=$! PID=$!
sleep 2 sleep 2
cd "$MNT" cd "$MNT"

View File

@ -25,7 +25,7 @@ printf "true" >"${EXP}/human"
printf "hi\n" >"${EXP}/greeting" printf "hi\n" >"${EXP}/greeting"
printf "bye" >"${EXP}/farewell" printf "bye" >"${EXP}/farewell"
ffs -o "$JSON" -m "$MNT" ../json/object.json & ffs --exact -o "$JSON" -m "$MNT" ../json/object.json &
PID=$! PID=$!
sleep 2 sleep 2
echo hi >"$MNT"/greeting echo hi >"$MNT"/greeting
@ -34,8 +34,8 @@ umount "$MNT" || fail unmount
sleep 1 sleep 1
kill -0 $PID >/dev/null 2>&1 && fail process kill -0 $PID >/dev/null 2>&1 && fail process
# remount w/o --newline, confirm that they're not there (except for greeting) # remount w/ --exact, confirm that they're not there (except for greeting)
ffs -m "$MNT" "$JSON" & ffs --exact -m "$MNT" "$JSON" &
sleep 2 sleep 2
case $(ls "$MNT") in case $(ls "$MNT") in
(eyes*farewell*fingernails*greeting*human*name) ;; (eyes*farewell*fingernails*greeting*human*name) ;;

View File

@ -25,7 +25,7 @@ printf "true" >"${EXP}/human"
printf "hi" >"${EXP}/greeting" printf "hi" >"${EXP}/greeting"
printf "bye" >"${EXP}/farewell" printf "bye" >"${EXP}/farewell"
ffs --newline -o "$JSON" -m "$MNT" ../json/object.json & ffs -o "$JSON" -m "$MNT" ../json/object.json &
PID=$! PID=$!
sleep 2 sleep 2
echo hi >"$MNT"/greeting echo hi >"$MNT"/greeting
@ -34,8 +34,8 @@ umount "$MNT" || fail unmount
sleep 1 sleep 1
kill -0 $PID >/dev/null 2>&1 && fail process kill -0 $PID >/dev/null 2>&1 && fail process
# remount w/o --newline, confirm that they're not there # remount w/ --exact, confirm that they're not there
ffs -m "$MNT" "$JSON" & ffs --exact -m "$MNT" "$JSON" &
sleep 2 sleep 2
case $(ls "$MNT") in case $(ls "$MNT") in
(eyes*farewell*fingernails*greeting*human*name) ;; (eyes*farewell*fingernails*greeting*human*name) ;;