Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: 2.1
executors:
base:
docker:
- image: circleci/golang:1.13
working_directory: /go/src/github.com/spatialcurrent/go-walker
jobs:
pre_deps_golang:
executor: base
steps:
- checkout
- run: make deps_go
- run: sudo chown -R circleci /go/src
- save_cache:
key: v1-go-src-{{ .Branch }}-{{ .Revision }}
paths:
- /go/src
test_go:
executor: base
steps:
- run: sudo chown -R circleci /go/src
- restore_cache:
keys:
- v1-go-src-{{ .Branch }}-{{ .Revision }}
- run: make deps_go_test
- run: make test_go
- run: make imports
- run: git diff --exit-code
workflows:
main:
jobs:
- pre_deps_golang
- test_go:
requires:
- pre_deps_golang
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
bin
dist
vendor
Gopkg.lock
*.so
*.h
.DS_Store
.npm
node_modules
npm-debug.*
package-lock.json
5 changes: 5 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go-walker is maintained by Spatial Current, Inc.

Authors:

* Patrick Dufour (pjdufour)
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Contributing to go-walker

## Contributor License Agreement

Thank you for your interest in contributing. You will first need to agree to the license. Simply post the following paragraph, with "your name" and "your github account" substituted as needed, to the first issue [#1](https://github.com/spatialcurrent/go-walker/issues/1). Otherwise, you can email us [here](mailto:opensource@spatialcurrent.io?subject=CLA).

I, **< YOUR NAME > (< YOUR GITHUB ACCOUNT >)**, agree to the license terms. My contributions to this repo are granted to **Spatial Current, Inc.** under a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable license and/or copyright is transferred.

## Versioning

This library is still in alpha (0.x.x), so versioning is not semantic yet.

## Authors

See [AUTHORS](https://github.com/spatialcurrent/go-walker/blob/master/AUTHORS) for a list of contributors.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Spatial Current, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# =================================================================
#
# Copyright (C) 2020 Spatial Current, Inc. - All Rights Reserved
# Released as open source under the MIT License. See LICENSE file.
#
# =================================================================

.PHONY: help
help: ## Print the help documentation
@grep -E '^[a-zA-Z_-\]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

#
# Dependencies
#

.PHONY: deps_go
deps_go: ## Install Go dependencies
go get -d -t ./...

.PHONY: deps_go_test
deps_go_test: ## Download Go dependencies for tests
go get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # download shadow
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # install shadow
go get -u github.com/kisielk/errcheck # download and install errcheck
go get -u github.com/client9/misspell/cmd/misspell # download and install misspell
go get -u github.com/gordonklaus/ineffassign # download and install ineffassign
go get -u honnef.co/go/tools/cmd/staticcheck # download and instal staticcheck
go get -u golang.org/x/tools/cmd/goimports # download and install goimports

deps_gopherjs: ## Install GopherJS
go get -u github.com/gopherjs/gopherjs

deps_javascript: ## Install dependencies for JavaScript tests
npm install .

#
# Go building, formatting, testing, and installing
#

.PHONY: fmt
fmt: ## Format Go source code
go fmt $$(go list ./... )

.PHONY: imports
imports: ## Update imports in Go source code
goimports -w -local github.com/spatialcurrent/go-walker,github.com/spatialcurrent/ $$(find . -iname '*.go')

.PHONY: vet
vet: ## Vet Go source code
go vet $$(go list ./... )

.PHONY: test_go
test_go: ## Run Go tests
bash scripts/test.sh

## Clean

clean: ## Clean artifacts
rm -fr bin
84 changes: 84 additions & 0 deletions pkg/iterator/Iterator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// =================================================================
//
// Copyright (C) 2020 Spatial Current, Inc. - All Rights Reserved
// Released as open source under the MIT License. See LICENSE file.
//
// =================================================================

package iterator

import (
"io"
"os"
"syscall"
)

type Iterator struct {
fd int
data []byte
buf []byte
names []string
eof bool
err error
}

func New(fd int) *Iterator {
return &Iterator{
fd: fd,
data: make([]byte, 0),
buf: make([]byte, os.Getpagesize()),
names: make([]string, 0),
eof: false,
err: nil,
}
}

func (it *Iterator) Reset(fd int) {
it.fd = fd
it.data = make([]byte, 0)
it.buf = make([]byte, os.Getpagesize())
it.names = make([]string, 0)
it.eof = false
it.err = nil
}

func (it *Iterator) Next() (string, error) {
if it.err != nil {
return "", it.err
}
if it.eof {
return "", io.EOF
}
if len(it.names) > 0 {
name := it.names[0]
it.names = it.names[1:]
return name, nil
}
for {
consumed, count, names := syscall.ParseDirent(it.data, 1, it.names[:0])
it.data = it.data[consumed:]
if count == 0 {
for {
n, err := syscall.ReadDirent(it.fd, it.buf)
if err != nil {
it.err = err
return "", err
}
if n == 0 {
it.eof = true
return "", io.EOF
}
it.data = append(it.data, it.buf[0:n]...)
break
}
continue
}
if count == 1 {
return names[0], nil
}
it.names = names[1:]
return names[0], nil
}
it.eof = true
return "", io.EOF
}
9 changes: 9 additions & 0 deletions pkg/iterator/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// =================================================================
//
// Copyright (C) 2020 Spatial Current, Inc. - All Rights Reserved
// Released as open source under the MIT License. See LICENSE file.
//
// =================================================================

// Package iterator is used for iterator through a list of directory entries.
package iterator
16 changes: 16 additions & 0 deletions pkg/modeutil/IsIrregular.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// =================================================================
//
// Copyright (C) 2020 Spatial Current, Inc. - All Rights Reserved
// Released as open source under the MIT License. See LICENSE file.
//
// =================================================================

package modeutil

import (
"os"
)

func IsIrregular(fi os.FileInfo) bool {
return fi.Mode()&os.ModeIrregular != 0
}
16 changes: 16 additions & 0 deletions pkg/modeutil/IsLink.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// =================================================================
//
// Copyright (C) 2020 Spatial Current, Inc. - All Rights Reserved
// Released as open source under the MIT License. See LICENSE file.
//
// =================================================================

package modeutil

import (
"os"
)

func IsLink(fi os.FileInfo) bool {
return fi.Mode()&os.ModeSymlink != 0
}
44 changes: 44 additions & 0 deletions pkg/modeutil/IsLink_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// =================================================================
//
// Copyright (C) 2020 Spatial Current, Inc. - All Rights Reserved
// Released as open source under the MIT License. See LICENSE file.
//
// =================================================================

package modeutil

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestIsLinkLstatRegular(t *testing.T) {
fi, err := os.Lstat("testdata/doc.1.txt")
assert.NoError(t, err)
assert.NotNil(t, fi)
assert.False(t, IsLink(fi))
}

func TestIsLinkLstatLink(t *testing.T) {
fi, err := os.Lstat("testdata/doc.2.txt")
assert.NoError(t, err)
assert.NotNil(t, fi)
assert.True(t, IsLink(fi))
}

func TestIsLinkLstatNamedPipe(t *testing.T) {
createNamedPipeIfNotExist("testdata/doc.3.txt")
fi, err := os.Lstat("testdata/doc.3.txt")
assert.NoError(t, err)
assert.NotNil(t, fi)
assert.False(t, IsLink(fi))
}

func TestIsLinkStatLink(t *testing.T) {
fi, err := os.Stat("testdata/doc.2.txt")
assert.NoError(t, err)
assert.NotNil(t, fi)
assert.False(t, IsLink(fi))
}
16 changes: 16 additions & 0 deletions pkg/modeutil/IsNamedPipe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// =================================================================
//
// Copyright (C) 2020 Spatial Current, Inc. - All Rights Reserved
// Released as open source under the MIT License. See LICENSE file.
//
// =================================================================

package modeutil

import (
"os"
)

func IsNamedPipe(fi os.FileInfo) bool {
return fi.Mode()&os.ModeNamedPipe != 0
}
44 changes: 44 additions & 0 deletions pkg/modeutil/IsNamedPipe_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// =================================================================
//
// Copyright (C) 2020 Spatial Current, Inc. - All Rights Reserved
// Released as open source under the MIT License. See LICENSE file.
//
// =================================================================

package modeutil

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestIsNamedPipeLstatRegular(t *testing.T) {
fi, err := os.Lstat("testdata/doc.1.txt")
assert.NoError(t, err)
assert.NotNil(t, fi)
assert.False(t, IsNamedPipe(fi))
}

func TestIsNamedPipeLstatLink(t *testing.T) {
fi, err := os.Lstat("testdata/doc.2.txt")
assert.NoError(t, err)
assert.NotNil(t, fi)
assert.False(t, IsNamedPipe(fi))
}

func TestIsNamedPipeLstatNamedPipe(t *testing.T) {
createNamedPipeIfNotExist("testdata/doc.3.txt")
fi, err := os.Lstat("testdata/doc.3.txt")
assert.NoError(t, err)
assert.NotNil(t, fi)
assert.True(t, IsNamedPipe(fi))
}

func TestIsNamedPipeStatLink(t *testing.T) {
fi, err := os.Stat("testdata/doc.2.txt")
assert.NoError(t, err)
assert.NotNil(t, fi)
assert.False(t, IsNamedPipe(fi))
}
Loading