*: initial thoughts

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2016-03-10 16:15:55 -05:00
commit 16b15e1c29
4 changed files with 334 additions and 0 deletions

39
cmd/gomtree/main.go Normal file
View File

@ -0,0 +1,39 @@
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strings"
)
func main() {
flag.Parse()
_ = mtree.DirectoryHierarchy{}
for _, file := range flag.Args() {
func() {
fh, err := os.Open(file)
if err != nil {
log.Println(err)
return
}
defer fh.Close()
s := bufio.NewScanner(fh)
for s.Scan() {
str := s.Text()
switch {
case strings.HasPrefix(str, "#"):
continue
default:
}
fmt.Printf("%q\n", str)
}
if err := s.Err(); err != nil {
log.Println("ERROR:", err)
}
}()
}
}

58
mtree.go Normal file
View File

@ -0,0 +1,58 @@
package mtree
import "io"
// Positioner responds with the newline delimited position
type Positioner interface {
Pos() int
}
// DirectoryHierarchy is the mapped structure for an mtree directory hierarchy
// spec
type DirectoryHierarchy struct {
Comments []Comment
Entries []Entry
}
// WriteTo simplifies the output of the resulting hierarchy spec
func (dh DirectoryHierarchy) WriteTo(w io.Writer) (n int64, err error) {
return 0, nil
}
// Comment stores arbitrary metadata for the spec. Sometimes "user", "machine",
// "tree", and "date". But most of the time, it includes the relative path of
// the directory being stepped into. Or a "signature" like `#mtree v2.0`,
type Comment struct {
Position int
Str string
// TODO(vbatts) include a comment line parser
}
// Pos returns the line of this comment
func (c Comment) Pos() int {
return c.Position
}
// Entry is each component of content in the mtree spec file
type Entry struct {
Position int // order in the spec
Name string // file or directory name
Keywords []string // TODO(vbatts) maybe a keyword typed set of values?
str string // raw string. needed?
Type EntryType
}
// Pos returns the line of this comment
func (e Entry) Pos() int {
return e.Position
}
type EntryType int
const (
SpecialType int = iota // line that has `/` prefix issue a "special" command (currently only /set and /unset)
FileType // indented line
DirectoryType // ^ matched line, that is not /set
PathStepType // .. - keywords/options are ignored
FullType // if the first word on the line has a `/` after the first character, it interpretted as a file pathname with options
)

41
mtree_test.go Normal file
View File

@ -0,0 +1,41 @@
package mtree
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"testing"
)
var testFiles = []string{
"testdata/source.mtree",
}
func TestParser(t *testing.T) {
for _, file := range testFiles {
func() {
fh, err := os.Open(file)
if err != nil {
log.Println(err)
return
}
defer fh.Close()
s := bufio.NewScanner(fh)
for s.Scan() {
str := s.Text()
switch {
case strings.HasPrefix(str, "#"):
continue
default:
}
fmt.Printf("%q\n", str)
}
if err := s.Err(); err != nil {
log.Println("ERROR:", err)
}
}()
}
}

196
testdata/source.mtree vendored Normal file
View File

@ -0,0 +1,196 @@
# user: vbatts
# machine: valse.usersys.redhat.com
# tree: /home/vbatts/src/vb/go-mtree
# date: Thu Mar 10 16:15:36 2016
# .
/set type=file uid=1000 gid=1000 mode=0664 nlink=1 flags=none
. type=dir mode=0775 nlink=5 size=4096 \
time=1457644509.817998120
.mtree.go.swp \
mode=0644 size=12288 time=1457644483.833957552 \
sha512digest=7efd38cc957b53e3d5abd25e9df9bde715a5e18dc18abfa8f0c0eaa9bca0fda32faad4972bd4d9b555270fa3b3b92e6a1e97ad1e3bfff14fc933284004f7e8d3
.mtree_test.go.swp \
mode=0644 size=12288 time=1457644509.813998114 \
sha512digest=2aaeb1e5f03a563de86a4c1f722bde40312bbecbe4504d67fb441240c049e6ad11294ef834114a05e620a390ee9f42c1c77b43bf1a4f2d47f128226183968a33
mtree.go size=1719 time=1457644447.020900074 \
sha512digest=2dee9f50ba167cd90d4f6e8494d4735c6b064c279ea4d26ed2c47552a5c0b82b0bdcadb214e0ca919a1768ce0e321e8d1bb71eacb9c5b4bb5fd4342967055a04
mtree.go~ size=1719 time=1457644447.012900062 \
sha512digest=2dee9f50ba167cd90d4f6e8494d4735c6b064c279ea4d26ed2c47552a5c0b82b0bdcadb214e0ca919a1768ce0e321e8d1bb71eacb9c5b4bb5fd4342967055a04
mtree_test.go \
size=581 time=1457644509.817998120 \
sha512digest=1b3ab2de2759df6e7d424d05ffd1d45101fd10ae86328abad1657e68044add69d83d6b3271225070f4f4154a7c0c995016077f8c7969890e068cd0a54b23f4b6
mtree_test.go~ \
size=581 time=1457644509.812998113 \
sha512digest=1b3ab2de2759df6e7d424d05ffd1d45101fd10ae86328abad1657e68044add69d83d6b3271225070f4f4154a7c0c995016077f8c7969890e068cd0a54b23f4b6
# ./.git
/set type=file uid=1000 gid=1000 mode=0775 nlink=1 flags=none
.git type=dir nlink=7 size=4096 time=1457644470.212936285
HEAD mode=0664 size=23 time=1454678171.602940889 \
sha512digest=76b199f1bffdc6d21547895431b0f85f3857df400225cbd1ae55e7ded09786a8a44e1cb21f1feff4951cf57c893043a0be696dcb0e4f5758a4d6081a833eb6cf
config mode=0664 size=92 time=1454678171.607940896 \
sha512digest=961231503987d2154696364e8e4d7b3aaf2d2abe5da55367b615a5d9e1bcda30824c30880bfdb8e9959444040d91cd3ec6fa225e8a36a93cfc182bf263d6e02a
description mode=0664 size=73 time=1454678171.602940889 \
sha512digest=f7e152f75b124c3e1c5d12f00427729d9eec4e2c1bf70d7606440a6600d003367eb178331e75ab976a61496e79c2c822020849d28ffd170946397b934611b471
index mode=0664 size=272 time=1457644470.212936285 \
sha512digest=fcecb444e3748cccfc498a63939f489f6456f1cf9e0e8ace21b7cdf8eecfb0e0a3db9bf6d449db2608752e5c0dbae786b4facb46f359555871b7e48d80b9a765
# ./.git/branches
branches type=dir nlink=2 size=4096 time=1454678171.596940880
# ./.git/branches
..
# ./.git/hooks
hooks type=dir nlink=2 size=4096 time=1454678171.600940886
applypatch-msg.sample \
size=478 time=1454678171.597940882 \
sha512digest=536cce804d84e25813993efdd240537b52d00ce9cdcecf1982f85096d56a521290104c825c00b370b2752201952a9616a3f4e28c5d27a5b4e4842101a2ff9bee
commit-msg.sample \
size=896 time=1454678171.598940883 \
sha512digest=d6bb7fa747f4625adf1877f546565cbe812ca7dd4168f7e9068e6732555d8737eba549546cf5946649e3f38de82d173aaf9c160a4c9f9445655258b4c5f955eb
post-update.sample \
size=189 time=1454678171.598940883 \
sha512digest=473ad124642571656276bf83b9ff63ab1804d3c23a5bdae52391c6f70a894849ac60c10c9d31deff3938922ce83b68b1e60c11592bbf7ea503f4acd39968cefa
pre-applypatch.sample \
size=424 time=1454678171.598940883 \
sha512digest=cb78aa7e9b9c146e5db65d86dd83f04e2b6942a06fab50c704a0fd900683f3b6ad1164e74afe2f267f6da91cdff0b9ab07713e12cefc6f8d741b5df194f4fda6
pre-commit.sample \
size=1642 time=1454678171.599940885 \
sha512digest=4a7ac2ed2ffe50d2a997c3477b5855c3d19423c295a82f7d660be3418217a183b0ce25f94ae2e350f4d93eda3b75a4bd62cf27f0685d8a837919bcc9e7e0962a
pre-push.sample \
size=1348 time=1454678171.599940885 \
sha512digest=37cd20a090494acb16c2255fe93dadeb409f2553afddc409dad5b5e99c9f5612a28eba397c0f3ae771e17edbe0a6c2a3af311154285e6d9c43e4cc4f06ba5b8d
pre-rebase.sample \
size=4951 time=1454678171.600940886 \
sha512digest=de9bdf513f383b3215e467c025ca851a0f2661b91811bfd441486b678e4d45e450ce9185a7c3ac2988bd6154d4983b3e29427623117e73623f2af43cf4b746da
prepare-commit-msg.sample \
size=1239 time=1454678171.600940886 \
sha512digest=fbf15f12136a413dd590e57392e6122714d67456beed50d9ef285e40076a138a7d44291b5642fe5c518dc56c640436caf6225d1a966e06c042b30e6a7d08dcef
update.sample \
size=3611 time=1454678171.601940888 \
sha512digest=f8e20df0e6c970fa809d5c9494cb9d5e32894fe20f23f6730df84f5fa065e52c55cca98d0db1ed17df53c606629c787ae56b6af6faca527f62c817f8cb148c1a
# ./.git/hooks
..
# ./.git/info
/set type=file uid=1000 gid=1000 mode=0664 nlink=1 flags=none
info type=dir mode=0775 nlink=2 size=4096 \
time=1454678171.601940888
exclude size=240 time=1454678171.601940888 \
sha512digest=9828c6ecdf91bf117416e17f4ee9caee2e1e37b6fb00b9ff04035ace17a3089b9d0a25c6baa1046c0e1c62d3da88838e8fca74ea82973d6b975905fde58f3072
# ./.git/info
..
# ./.git/objects
/set type=file uid=1000 gid=1000 mode=0775 nlink=1 flags=none
objects type=dir nlink=7 size=4096 time=1457644470.212936285
# ./.git/objects/35
/set type=file uid=1000 gid=1000 mode=0444 nlink=1 flags=none
35 type=dir mode=0775 nlink=2 size=4096 \
time=1457644470.212936285
51bcca10021bb56f13dd57a84b97cdf7fda0cf \
size=344 time=1457644470.212936285 \
sha512digest=cc9cbb88b1c060f78a06d65decb59f2e4f7cafe25fc962d549b1826b91f2b27f22d13ec104acdea1dc30fa22c533fa88da9df2785a782dacbf93264741099043
# ./.git/objects/35
..
# ./.git/objects/45
45 type=dir mode=0775 nlink=2 size=4096 \
time=1457644470.212936285
15ff8d078d5291b75e99cbaa3e6c5e83ffaa2e \
size=363 time=1457644470.212936285 \
sha512digest=b4cb2c25df4a6d5a158b4d945d1c1bd26a17b286c472bb9ad5b43624ee09c01b24c817875ac7611992f2b45eea0287cb0d8e4ae257ed054d1e33ae6f481728c8
# ./.git/objects/45
..
# ./.git/objects/88
88 type=dir mode=0775 nlink=2 size=4096 \
time=1454678174.768945501
2ba9732d762797f0f338de29bf79a8c0b7a679 \
size=30 time=1454678174.768945501 \
sha512digest=cc95f98c49e284de74626cc5da73ff54388a65fd796f532ae070c09635784ae2dac04537e1d2b1c73fae7be8ad96c96fab3ddddd943a7abc7b3ee8741fe56de5
# ./.git/objects/88
..
# ./.git/objects/info
info type=dir mode=0775 nlink=2 size=4096 \
time=1454678171.609940899
# ./.git/objects/info
..
# ./.git/objects/pack
pack type=dir mode=0775 nlink=2 size=4096 \
time=1454678171.609940899
# ./.git/objects/pack
..
# ./.git/objects
..
# ./.git/refs
/set type=file uid=1000 gid=1000 mode=0775 nlink=1 flags=none
refs type=dir nlink=4 size=4096 time=1454678171.595940879
# ./.git/refs/heads
heads type=dir nlink=2 size=4096 time=1454678171.595940879
# ./.git/refs/heads
..
# ./.git/refs/tags
tags type=dir nlink=2 size=4096 time=1454678171.595940879
# ./.git/refs/tags
..
# ./.git/refs
..
# ./.git
..
# ./cmd
cmd type=dir nlink=3 size=4096 time=1457644245.753596701
# ./cmd/gomtree
/set type=file uid=1000 gid=1000 mode=0664 nlink=1 flags=none
gomtree type=dir mode=0775 nlink=2 size=4096 \
time=1457644313.182697118
.main.go.swp \
mode=0644 size=12288 time=1457644334.048728193 \
sha512digest=ac1a05940c2033962a7ba6878a25aeeac84df3d41548b15c2b3ae283c8090012f3646821906b0edc4b716cf3a220536c862ea370ce235bffc7b7520f77df8903
main.go size=552 time=1457644313.182697118 \
sha512digest=519009a7756506e7aac81734b9701ac33aa0c22b1866abdc1fc1550e6c4e7164fa794d60f524116e7cfcdc9456f8637f504359749690f8199008263925350dad
main.go~ size=552 time=1457644313.171697102 \
sha512digest=519009a7756506e7aac81734b9701ac33aa0c22b1866abdc1fc1550e6c4e7164fa794d60f524116e7cfcdc9456f8637f504359749690f8199008263925350dad
# ./cmd/gomtree
..
# ./cmd
..
# ./testdata
testdata type=dir mode=0775 nlink=2 size=4096 \
time=1457644536.529039825
Downloads.mtree \
size=31406 time=1457644391.210813319 \
sha512digest=a31c61a8907078a82c1ad542ded518e10e862dcf9f561970a6174652d716c4e1ea745410c6a69d7382b13607e85426a190268955d4ecb657990c3fa456e39b46
source.mtree \
size=8192 time=1457644536.536039836 \
sha512digest=9748642c0ef6784611d155030067ccc5cdad5d51b4dc61b103da08377bd75aa3132756dcdb81c850e6555de5e845f26e22996b8bf1f76d39e71128585fbe6d17
# ./testdata
..
..