From 5a0100bfb1ee2d1b23796a5ebae8d4a01bb5467c Mon Sep 17 00:00:00 2001 From: Michael Greenberg Date: Thu, 24 Jun 2021 11:05:57 -0400 Subject: [PATCH] change default behavior to modify newlines; update readme --- README.md | 78 +++++++++++------------------------ src/config.rs | 2 +- src/format.rs | 1 + src/main.rs | 8 ++-- tests/basic_object_exact.sh | 2 +- tests/basic_object_newline.sh | 2 +- tests/exact_cleanup.sh | 6 +-- tests/newline_cleanup.sh | 6 +-- 8 files changed, 38 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 855ff08..d78f429 100644 --- a/README.md +++ b/README.md @@ -15,61 +15,31 @@ know. Run `ffs [mountpoint] [file]` to mount a file at a given mountpoint. ```shell-session -$ ffs mnt json_eg1.json & -[1] 80762 -$ tree mnt -mnt -└── glossary - ├── GlossDiv - │   ├── GlossList - │   │   └── GlossEntry - │   │   ├── Abbrev - │   │   ├── Acronym - │   │   ├── GlossDef - │   │   │   ├── GlossSeeAlso - │   │   │   │   ├── 0 - │   │   │   │   └── 1 - │   │   │   └── para - │   │   ├── GlossSee - │   │   ├── GlossTerm - │   │   ├── ID - │   │   └── SortAs - │   └── title - └── title +$ cat object.json +{ "name": "Michael Greenberg", "eyes": 2, "fingernails": 10, "human": true } +$ ffs -o object_edited.json object.json & +[1] 60182 +$ tree object +object +├── eyes +├── fingernails +├── human +└── name -6 directories, 11 files -$ cat mnt/glossary/GlossDiv/GlossList/GlossEntry/Abbrev -ISO 8879:1986$ cat mnt/glossary/GlossDiv/GlossList/GlossEntry/Acronym -SGML$ cat mnt/glossary/title -example glossary$ cat json_eg1.json -{ - "glossary": { - "title": "example glossary", - "GlossDiv": { - "title": "S", - "GlossList": { - "GlossEntry": { - "ID": "SGML", - "SortAs": "SGML", - "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 -$ +0 directories, 4 files +$ echo Mikey Indiana >object/name +$ echo 1 >object/nose +$ mkdir object/pockets +$ cd object/pockets/ +$ echo keys >pants +$ echo pen >shirt +$ cd .. +$ cd .. +$ umount object +$ +[1]+ Done ffs -o object_edited.json object.json +$ cat object_edited.json +{"eyes":2,"fingernails":10,"human":true,"name":"Mikey Indiana","nose":1,"pockets":{"pants":"keys","shirt":"pen"}} ``` # External dependencies diff --git a/src/config.rs b/src/config.rs index 0f9e11e..f825c62 100644 --- a/src/config.rs +++ b/src/config.rs @@ -81,7 +81,7 @@ impl Default for Config { gid: 501, filemode: 0o644, dirmode: 0o755, - add_newlines: false, + add_newlines: true, pad_element_names: true, base64: base64::STANDARD, try_decode_base64: false, diff --git a/src/format.rs b/src/format.rs index 2979ab4..b738bad 100644 --- a/src/format.rs +++ b/src/format.rs @@ -299,6 +299,7 @@ where if fs.config.add_newlines && contents.ends_with('\n') { contents.truncate(contents.len() - 1); } + // TODO 2021-06-24 trim? V::from_string(contents, &fs.config) } Err(_) => V::from_bytes(contents, &fs.config), diff --git a/src/main.rs b/src/main.rs index 2fd3d25..62af2d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,9 +62,9 @@ fn main() { .default_value("755") ) .arg( - Arg::with_name("NEWLINE") - .help("Add a newline to the end of values that don't already have them") - .long("newline") + Arg::with_name("EXACT") + .help("Don't add newlines to the end of values that don't already have them (or strip them when loading)") + .long("exact") ) .arg( Arg::with_name("UNPADDED") @@ -145,7 +145,7 @@ fn main() { .init(); } - config.add_newlines = args.is_present("NEWLINE"); + config.add_newlines = !args.is_present("EXACT"); config.pad_element_names = !args.is_present("UNPADDED"); config.read_only = args.is_present("READONLY"); config.filemode = match u16::from_str_radix(args.value_of("FILEMODE").unwrap(), 8) { diff --git a/tests/basic_object_exact.sh b/tests/basic_object_exact.sh index cdc944b..da0b297 100755 --- a/tests/basic_object_exact.sh +++ b/tests/basic_object_exact.sh @@ -22,7 +22,7 @@ printf "10" >"${EXP}/fingernails" printf "true" >"${EXP}/human" printf "" >"${EXP}/problems" -ffs -m "$MNT" ../json/object_null.json & +ffs --exact -m "$MNT" ../json/object_null.json & PID=$! sleep 2 cd "$MNT" diff --git a/tests/basic_object_newline.sh b/tests/basic_object_newline.sh index ec44c34..821dc75 100755 --- a/tests/basic_object_newline.sh +++ b/tests/basic_object_newline.sh @@ -22,7 +22,7 @@ printf "10\n" >"${EXP}/fingernails" printf "true\n" >"${EXP}/human" printf "" >"${EXP}/problems" -ffs --newline -m "$MNT" ../json/object_null.json & +ffs -m "$MNT" ../json/object_null.json & PID=$! sleep 2 cd "$MNT" diff --git a/tests/exact_cleanup.sh b/tests/exact_cleanup.sh index b5a4f80..fd62081 100755 --- a/tests/exact_cleanup.sh +++ b/tests/exact_cleanup.sh @@ -25,7 +25,7 @@ printf "true" >"${EXP}/human" printf "hi\n" >"${EXP}/greeting" printf "bye" >"${EXP}/farewell" -ffs -o "$JSON" -m "$MNT" ../json/object.json & +ffs --exact -o "$JSON" -m "$MNT" ../json/object.json & PID=$! sleep 2 echo hi >"$MNT"/greeting @@ -34,8 +34,8 @@ umount "$MNT" || fail unmount sleep 1 kill -0 $PID >/dev/null 2>&1 && fail process -# remount w/o --newline, confirm that they're not there (except for greeting) -ffs -m "$MNT" "$JSON" & +# remount w/ --exact, confirm that they're not there (except for greeting) +ffs --exact -m "$MNT" "$JSON" & sleep 2 case $(ls "$MNT") in (eyes*farewell*fingernails*greeting*human*name) ;; diff --git a/tests/newline_cleanup.sh b/tests/newline_cleanup.sh index 76d2dba..ea96988 100755 --- a/tests/newline_cleanup.sh +++ b/tests/newline_cleanup.sh @@ -25,7 +25,7 @@ printf "true" >"${EXP}/human" printf "hi" >"${EXP}/greeting" printf "bye" >"${EXP}/farewell" -ffs --newline -o "$JSON" -m "$MNT" ../json/object.json & +ffs -o "$JSON" -m "$MNT" ../json/object.json & PID=$! sleep 2 echo hi >"$MNT"/greeting @@ -34,8 +34,8 @@ umount "$MNT" || fail unmount sleep 1 kill -0 $PID >/dev/null 2>&1 && fail process -# remount w/o --newline, confirm that they're not there -ffs -m "$MNT" "$JSON" & +# remount w/ --exact, confirm that they're not there +ffs --exact -m "$MNT" "$JSON" & sleep 2 case $(ls "$MNT") in (eyes*farewell*fingernails*greeting*human*name) ;;