1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-05-17 15:06:47 +08:00

remove Godeps

fixes #2722

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
This commit is contained in:
Steven Allen
2018-09-07 15:01:40 -07:00
parent eb45644104
commit 0252710020
43 changed files with 42 additions and 1884 deletions

53
Godeps/Godeps.json generated
View File

@ -1,53 +0,0 @@
{
"ImportPath": "github.com/ipfs/go-ipfs",
"GoVersion": "go1.5.2",
"Packages": [
"./..."
],
"Deps": [
{
"ImportPath": "bazil.org/fuse",
"Rev": "e4fcc9a2c7567d1c42861deebeb483315d222262"
},
{
"ImportPath": "github.com/camlistore/lock",
"Rev": "ae27720f340952636b826119b58130b9c1a847a0"
},
{
"ImportPath": "github.com/codahale/hdrhistogram",
"Rev": "5fd85ec0b4e2dd5d4158d257d943f2e586d86b62"
},
{
"ImportPath": "github.com/codahale/metrics",
"Rev": "7c37910bc765e705301b159683480bdd44555c91"
},
{
"ImportPath": "github.com/hashicorp/golang-lru",
"Rev": "253b2dc1ca8bae42c3b5b6e53dd2eab1a7551116"
},
{
"ImportPath": "github.com/jbenet/go-os-rename",
"Rev": "3ac97f61ef67a6b87b95c1282f6c317ed0e693c2"
},
{
"ImportPath": "github.com/jbenet/go-random",
"Rev": "cd535bd25356746b9b1e824871dda7da932460e2"
},
{
"ImportPath": "github.com/jbenet/go-random-files",
"Rev": "737479700b40b4b50e914e963ce8d9d44603e3c8"
},
{
"ImportPath": "github.com/mitchellh/go-homedir",
"Rev": "1f6da4a72e57d4e7edd4a7295a585e0a3999a2d4"
},
{
"ImportPath": "github.com/syndtr/gosnappy/snappy",
"Rev": "156a073208e131d7d2e212cb749feae7c339e846"
},
{
"ImportPath": "github.com/texttheater/golang-levenshtein/levenshtein",
"Rev": "dfd657628c58d3eeaa26391097853b2473c8b94e"
}
]
}

View File

@ -1,23 +0,0 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test

View File

@ -1,362 +0,0 @@
Mozilla Public License, version 2.0
1. Definitions
1.1. "Contributor"
means each individual or legal entity that creates, contributes to the
creation of, or owns Covered Software.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used by a
Contributor and that particular Contributor's Contribution.
1.3. "Contribution"
means Covered Software of a particular Contributor.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached the
notice in Exhibit A, the Executable Form of such Source Code Form, and
Modifications of such Source Code Form, in each case including portions
thereof.
1.5. "Incompatible With Secondary Licenses"
means
a. that the initial Contributor has attached the notice described in
Exhibit B to the Covered Software; or
b. that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the terms of
a Secondary License.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in a
separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible, whether
at the time of the initial grant or subsequently, any and all of the
rights conveyed by this License.
1.10. "Modifications"
means any of the following:
a. any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered Software; or
b. any new file in Source Code Form that contains any Covered Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the License,
by the making, using, selling, offering for sale, having made, import,
or transfer of either its Contributions or its Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU Lesser
General Public License, Version 2.1, the GNU Affero General Public
License, Version 3.0, or any later versions of those licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that controls, is
controlled by, or is under common control with You. For purposes of this
definition, "control" means (a) the power, direct or indirect, to cause
the direction or management of such entity, whether by contract or
otherwise, or (b) ownership of more than fifty percent (50%) of the
outstanding shares or beneficial ownership of such entity.
2. License Grants and Conditions
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
a. under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
b. under Patent Claims of such Contributor to make, use, sell, offer for
sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
a. for any code that a Contributor has removed from Covered Software; or
b. for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
c. under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights to
grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
Section 2.1.
3. Responsibilities
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
a. such Covered Software must also be made available in Source Code Form,
as described in Section 3.1, and You must inform recipients of the
Executable Form how they can obtain a copy of such Source Code Form by
reasonable means in a timely manner, at a charge no more than the cost
of distribution to the recipient; and
b. You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter the
recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty, or
limitations of liability) contained within the Source Code Form of the
Covered Software, except that You may alter any license notices to the
extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
If it is impossible for You to comply with any of the terms of this License
with respect to some or all of the Covered Software due to statute,
judicial order, or regulation then You must: (a) comply with the terms of
this License to the maximum extent possible; and (b) describe the
limitations and the code they affect. Such description must be placed in a
text file included with all distributions of the Covered Software under
this License. Except to the extent prohibited by statute or regulation,
such description must be sufficiently detailed for a recipient of ordinary
skill to be able to understand it.
5. Termination
5.1. The rights granted under this License will terminate automatically if You
fail to comply with any of its terms. However, if You become compliant,
then the rights granted under this License from a particular Contributor
are reinstated (a) provisionally, unless and until such Contributor
explicitly and finally terminates Your grants, and (b) on an ongoing
basis, if such Contributor fails to notify You of the non-compliance by
some reasonable means prior to 60 days after You have come back into
compliance. Moreover, Your grants from a particular Contributor are
reinstated on an ongoing basis if such Contributor notifies You of the
non-compliance by some reasonable means, this is the first time You have
received notice of non-compliance with this License from such
Contributor, and You become compliant prior to 30 days after Your receipt
of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
license agreements (excluding distributors and resellers) which have been
validly granted by You or Your distributors under this License prior to
termination shall survive termination.
6. Disclaimer of Warranty
Covered Software is provided under this License on an "as is" basis,
without warranty of any kind, either expressed, implied, or statutory,
including, without limitation, warranties that the Covered Software is free
of defects, merchantable, fit for a particular purpose or non-infringing.
The entire risk as to the quality and performance of the Covered Software
is with You. Should any Covered Software prove defective in any respect,
You (not any Contributor) assume the cost of any necessary servicing,
repair, or correction. This disclaimer of warranty constitutes an essential
part of this License. No use of any Covered Software is authorized under
this License except under this disclaimer.
7. Limitation of Liability
Under no circumstances and under no legal theory, whether tort (including
negligence), contract, or otherwise, shall any Contributor, or anyone who
distributes Covered Software as permitted above, be liable to You for any
direct, indirect, special, incidental, or consequential damages of any
character including, without limitation, damages for lost profits, loss of
goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses, even if such party shall have been
informed of the possibility of such damages. This limitation of liability
shall not apply to liability for death or personal injury resulting from
such party's negligence to the extent applicable law prohibits such
limitation. Some jurisdictions do not allow the exclusion or limitation of
incidental or consequential damages, so this exclusion and limitation may
not apply to You.
8. Litigation
Any litigation relating to this License may be brought only in the courts
of a jurisdiction where the defendant maintains its principal place of
business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions. Nothing
in this Section shall prevent a party's ability to bring cross-claims or
counter-claims.
9. Miscellaneous
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides that
the language of a contract shall be construed against the drafter shall not
be used to construe this License against a Contributor.
10. Versions of the License
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses If You choose to distribute Source Code Form that is
Incompatible With Secondary Licenses under the terms of this version of
the License, the notice described in Exhibit B of this License must be
attached.
Exhibit A - Source Code Form License Notice
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file,
then You may include the notice in a location (such as a LICENSE file in a
relevant directory) where a recipient would be likely to look for such a
notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
This Source Code Form is "Incompatible
With Secondary Licenses", as defined by
the Mozilla Public License, v. 2.0.

View File

@ -1,25 +0,0 @@
golang-lru
==========
This provides the `lru` package which implements a fixed-size
thread safe LRU cache. It is based on the cache in Groupcache.
Documentation
=============
Full docs are available on [Godoc](http://godoc.org/github.com/hashicorp/golang-lru)
Example
=======
Using the LRU is very simple:
```go
l, _ := New(128)
for i := 0; i < 256; i++ {
l.Add(i, nil)
}
if l.Len() != 128 {
panic("bad len: %v", l.Len())
}
```

View File

@ -1,134 +0,0 @@
// This package provides a simple LRU cache. It is based on the
// LRU implementation in groupcache:
// https://github.com/golang/groupcache/tree/master/lru
package lru
import (
"container/list"
"errors"
"sync"
)
// Cache is a thread-safe fixed size LRU cache.
type Cache struct {
size int
evictList *list.List
items map[interface{}]*list.Element
lock sync.Mutex
}
// entry is used to hold a value in the evictList
type entry struct {
key interface{}
value interface{}
}
// New creates an LRU of the given size
func New(size int) (*Cache, error) {
if size <= 0 {
return nil, errors.New("Must provide a positive size")
}
c := &Cache{
size: size,
evictList: list.New(),
items: make(map[interface{}]*list.Element, size),
}
return c, nil
}
// Purge is used to completely clear the cache
func (c *Cache) Purge() {
c.lock.Lock()
defer c.lock.Unlock()
c.evictList = list.New()
c.items = make(map[interface{}]*list.Element, c.size)
}
// Add adds a value to the cache.
func (c *Cache) Add(key, value interface{}) {
c.lock.Lock()
defer c.lock.Unlock()
// Check for existing item
if ent, ok := c.items[key]; ok {
c.evictList.MoveToFront(ent)
ent.Value.(*entry).value = value
return
}
// Add new item
ent := &entry{key, value}
entry := c.evictList.PushFront(ent)
c.items[key] = entry
// Verify size not exceeded
if c.evictList.Len() > c.size {
c.removeOldest()
}
}
// Get looks up a key's value from the cache.
func (c *Cache) Get(key interface{}) (value interface{}, ok bool) {
c.lock.Lock()
defer c.lock.Unlock()
if ent, ok := c.items[key]; ok {
c.evictList.MoveToFront(ent)
return ent.Value.(*entry).value, true
}
return
}
// Remove removes the provided key from the cache.
func (c *Cache) Remove(key interface{}) {
c.lock.Lock()
defer c.lock.Unlock()
if ent, ok := c.items[key]; ok {
c.removeElement(ent)
}
}
// RemoveOldest removes the oldest item from the cache.
func (c *Cache) RemoveOldest() {
c.lock.Lock()
defer c.lock.Unlock()
c.removeOldest()
}
// Keys returns a slice of the keys in the cache.
func (c *Cache) Keys() []interface{} {
c.lock.Lock()
defer c.lock.Unlock()
keys := make([]interface{}, len(c.items))
i := 0
for k := range c.items {
keys[i] = k
i++
}
return keys
}
// removeOldest removes the oldest item from the cache.
func (c *Cache) removeOldest() {
ent := c.evictList.Back()
if ent != nil {
c.removeElement(ent)
}
}
// removeElement is used to remove a given list element from the cache
func (c *Cache) removeElement(e *list.Element) {
c.evictList.Remove(e)
kv := e.Value.(*entry)
delete(c.items, kv.key)
}
// Len returns the number of items in the cache.
func (c *Cache) Len() int {
c.lock.Lock()
defer c.lock.Unlock()
return c.evictList.Len()
}

View File

@ -1,48 +0,0 @@
package lru
import "testing"
func TestLRU(t *testing.T) {
l, err := New(128)
if err != nil {
t.Fatalf("err: %v", err)
}
for i := 0; i < 256; i++ {
l.Add(i, i)
}
if l.Len() != 128 {
t.Fatalf("bad len: %v", l.Len())
}
for _, k := range l.Keys() {
if v, ok := l.Get(k); !ok || v != k {
t.Fatalf("bad key: %v", k)
}
}
for i := 0; i < 128; i++ {
_, ok := l.Get(i)
if ok {
t.Fatalf("should be evicted")
}
}
for i := 128; i < 256; i++ {
_, ok := l.Get(i)
if !ok {
t.Fatalf("should not be evicted")
}
}
for i := 128; i < 192; i++ {
l.Remove(i)
_, ok := l.Get(i)
if ok {
t.Fatalf("should be deleted")
}
}
l.Purge()
if l.Len() != 0 {
t.Fatalf("bad len: %v", l.Len())
}
if _, ok := l.Get(200); ok {
t.Fatalf("should contain nothing")
}
}

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2014 Juan Batiz-Benet
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.

View File

@ -1,5 +0,0 @@
build:
cd random-files && go build
install:
cd random-files && go install

View File

@ -1,108 +0,0 @@
# go-random-files - create random fs hierarchies
Useful for testing filesystems.
```
# library
go get -u github.com/jbenet/go-random-files
# binary
go get -u github.com/jbenet/go-random-files/random-files
```
### Library godoc: https://godoc.org/github.com/jbenet/go-random-files
# random-files - create random fs hierarchies
See more about the binary at: github.com/jbenet/go-random-files/tree/master/random-files
Useful for testing filesystems.
## Install
```
go get -u github.com/jbenet/go-random-files/random-files
```
## Usage
```sh
> random-files --help
usage: random-files [options] <path>...
Write a random filesystem hierarchy to each <path>
Options:
-alphabet="easy": alphabet for filenames {easy, hard}
-depth=2: fanout depth - how deep the hierarchy goes
-dirs=5: fanout dirs - number of dirs per dir (or max)
-files=10: fanout files - number of files per dir (or max
-filesize=4096: filesize - how big to make each file (or max)
-q=false: quiet output
-random-crypto=false: use cryptographic randomness for files
-random-fanout=false: randomize fanout numbers
-random-size=true: randomize filesize
-seed=0: random seed - 0 for current time
```
### Examples
```sh
> random-files --depth=2 --files=3 foo
foo/h20uo3jrpihb
foo/x6tef1
foo/jh0c2vdci
foo/fden012m368
foo/fden012m368/p6n0chy4kg
foo/fden012m368/h92_
foo/fden012m368/kvjiya98p3
foo/e_i6hwav1tb
foo/e_i6hwav1tb/oj0-a
foo/e_i6hwav1tb/1-pfgvim
foo/e_i6hwav1tb/s_unf
foo/bgvy8x-_hsm
foo/bgvy8x-_hsm/98zcoz-9ng
foo/bgvy8x-_hsm/j0see3qv
foo/bgvy8x-_hsm/qntuf0r
foo/6zjkw3ejm2awwt
foo/6zjkw3ejm2awwt/iba52dh1lhnewh
foo/6zjkw3ejm2awwt/n1bwcv5zpe
foo/6zjkw3ejm2awwt/o8k89cc
foo/efp_6
foo/efp_6/qfap2
foo/efp_6/v_kl_wlefsaa
foo/efp_6/r7sdbph
```
It made:
```
> tree foo
foo
├── 6zjkw3ejm2awwt
│   ├── iba52dh1lhnewh
│   ├── n1bwcv5zpe
│   └── o8k89cc
├── bgvy8x-_hsm
│   ├── 98zcoz-9ng
│   ├── j0see3qv
│   └── qntuf0r
├── e_i6hwav1tb
│   ├── 1-pfgvim
│   ├── oj0-a
│   └── s_unf
├── efp_6
│   ├── qfap2
│   ├── r7sdbph
│   └── v_kl_wlefsaa
├── fden012m368
│   ├── h92_
│   ├── kvjiya98p3
│   └── p6n0chy4kg
├── h20uo3jrpihb
├── jh0c2vdci
└── x6tef1
5 directories, 18 files
```

View File

@ -1,110 +0,0 @@
package randomfiles
import (
"fmt"
"io"
"math/rand"
"os"
"path"
)
type Options struct {
Out io.Writer // output progress
Source io.Reader // randomness source
FileSize int // the size per file.
Alphabet []rune // for filenames
FanoutDepth int // how deep the hierarchy goes
FanoutFiles int // how many files per dir
FanoutDirs int // how many dirs per dir
RandomSeed int64 // use a random seed. if 0, use a random seed
RandomSize bool // randomize file sizes
RandomFanout bool // randomize fanout numbers
}
func WriteRandomFiles(root string, depth int, opts *Options) error {
numfiles := opts.FanoutFiles
if opts.RandomFanout {
numfiles = rand.Intn(numfiles) + 1
}
for i := 0; i < numfiles; i++ {
if err := WriteRandomFile(root, opts); err != nil {
return err
}
}
if depth+1 <= opts.FanoutDepth {
numdirs := opts.FanoutDirs
if opts.RandomFanout {
numdirs = rand.Intn(numdirs) + 1
}
for i := 0; i < numdirs; i++ {
if err := WriteRandomDir(root, depth+1, opts); err != nil {
return err
}
}
}
return nil
}
var FilenameSize = 16
var RunesEasy = []rune("abcdefghijklmnopqrstuvwxyz01234567890-_")
var RunesHard = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890!@#$%^&*()-_+= ;.,<>'\"[]{}() ")
func RandomFilename(length int, alphabet []rune) string {
b := make([]rune, length)
for i := range b {
b[i] = alphabet[rand.Intn(len(alphabet))]
}
return string(b)
}
func WriteRandomFile(root string, opts *Options) error {
filesize := int64(opts.FileSize)
if opts.RandomSize {
filesize = rand.Int63n(filesize) + 1
}
n := rand.Intn(FilenameSize-4) + 4
name := RandomFilename(n, opts.Alphabet)
filepath := path.Join(root, name)
f, err := os.Create(filepath)
if err != nil {
return err
}
if _, err := io.CopyN(f, opts.Source, filesize); err != nil {
return err
}
if opts.Out != nil {
fmt.Fprintln(opts.Out, filepath)
}
return f.Close()
}
func WriteRandomDir(root string, depth int, opts *Options) error {
if depth > opts.FanoutDepth {
return nil
}
n := rand.Intn(FilenameSize-4) + 4
name := RandomFilename(n, opts.Alphabet)
root = path.Join(root, name)
if err := os.MkdirAll(root, 0755); err != nil {
return err
}
if opts.Out != nil {
fmt.Fprintln(opts.Out, root)
}
return WriteRandomFiles(root, depth, opts)
}

View File

@ -1 +0,0 @@
random-files

View File

@ -1,90 +0,0 @@
# random-files - create random fs hierarchies
random-files creates random fs hierarchies. Useful for testing filesystems.
## Install
```
go get -u github.com/jbenet/go-random-files/random-files
```
## Usage
```sh
> random-files --help
usage: random-files [options] <path>...
Write a random filesystem hierarchy to each <path>
Options:
-alphabet="easy": alphabet for filenames {easy, hard}
-depth=2: fanout depth - how deep the hierarchy goes
-dirs=5: fanout dirs - number of dirs per dir (or max)
-files=10: fanout files - number of files per dir (or max
-filesize=4096: filesize - how big to make each file (or max)
-q=false: quiet output
-random-crypto=false: use cryptographic randomness for files
-random-fanout=false: randomize fanout numbers
-random-size=true: randomize filesize
-seed=0: random seed - 0 for current time
```
## Examples
```sh
> random-files --depth=2 --files=3 foo
foo/h20uo3jrpihb
foo/x6tef1
foo/jh0c2vdci
foo/fden012m368
foo/fden012m368/p6n0chy4kg
foo/fden012m368/h92_
foo/fden012m368/kvjiya98p3
foo/e_i6hwav1tb
foo/e_i6hwav1tb/oj0-a
foo/e_i6hwav1tb/1-pfgvim
foo/e_i6hwav1tb/s_unf
foo/bgvy8x-_hsm
foo/bgvy8x-_hsm/98zcoz-9ng
foo/bgvy8x-_hsm/j0see3qv
foo/bgvy8x-_hsm/qntuf0r
foo/6zjkw3ejm2awwt
foo/6zjkw3ejm2awwt/iba52dh1lhnewh
foo/6zjkw3ejm2awwt/n1bwcv5zpe
foo/6zjkw3ejm2awwt/o8k89cc
foo/efp_6
foo/efp_6/qfap2
foo/efp_6/v_kl_wlefsaa
foo/efp_6/r7sdbph
```
It made:
```
> tree foo
foo
├── 6zjkw3ejm2awwt
│   ├── iba52dh1lhnewh
│   ├── n1bwcv5zpe
│   └── o8k89cc
├── bgvy8x-_hsm
│   ├── 98zcoz-9ng
│   ├── j0see3qv
│   └── qntuf0r
├── e_i6hwav1tb
│   ├── 1-pfgvim
│   ├── oj0-a
│   └── s_unf
├── efp_6
│   ├── qfap2
│   ├── r7sdbph
│   └── v_kl_wlefsaa
├── fden012m368
│   ├── h92_
│   ├── kvjiya98p3
│   └── p6n0chy4kg
├── h20uo3jrpihb
├── jh0c2vdci
└── x6tef1
5 directories, 18 files
```

View File

@ -1,119 +0,0 @@
package main
import (
crand "crypto/rand"
"errors"
"flag"
"fmt"
"math/rand"
"os"
"time"
randomfiles "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random-files"
ringreader "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random-files/ringreader"
)
var usage = `usage: %s [options] <path>...
Write a random filesystem hierarchy to each <path>
Options:
`
// flags
var opts randomfiles.Options
var quiet bool
var alphabet string
var paths []string
var cryptorand bool
func init() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, usage, os.Args[0])
flag.PrintDefaults()
}
flag.BoolVar(&quiet, "q", false, "quiet output")
flag.BoolVar(&cryptorand, "random-crypto", false, "use cryptographic randomness for files")
flag.StringVar(&alphabet, "alphabet", "easy", "alphabet for filenames {easy, hard}")
flag.IntVar(&opts.FileSize, "filesize", 4096, "filesize - how big to make each file (or max)")
flag.IntVar(&opts.FanoutDepth, "depth", 2, "fanout depth - how deep the hierarchy goes")
flag.IntVar(&opts.FanoutDirs, "dirs", 5, "fanout dirs - number of dirs per dir (or max)")
flag.IntVar(&opts.FanoutFiles, "files", 10, "fanout files - number of files per dir (or max")
flag.Int64Var(&opts.RandomSeed, "seed", 0, "random seed - 0 for current time")
flag.BoolVar(&opts.RandomFanout, "random-fanout", false, "randomize fanout numbers")
flag.BoolVar(&opts.RandomSize, "random-size", true, "randomize filesize")
}
func parseArgs() error {
flag.Parse()
switch alphabet {
case "easy":
opts.Alphabet = randomfiles.RunesEasy
case "hard":
opts.Alphabet = randomfiles.RunesHard
default:
return errors.New("alphabet must be one of: easy, hard")
}
paths = flag.Args()
if len(paths) < 1 {
flag.Usage()
os.Exit(0)
}
if !quiet {
opts.Out = os.Stdout
}
switch opts.RandomSeed {
case 0:
rand.Seed(time.Now().UnixNano())
default:
rand.Seed(opts.RandomSeed)
}
// prepare randomn source.
if cryptorand {
opts.Source = crand.Reader
} else {
// if not crypto, we don't need a lot of random
// data. we just need to sample from a sequence.
s := 16777216 // 16MB
r, err := ringreader.NewReader(s)
if err != nil {
return err
}
opts.Source = r
}
return nil
}
func run() error {
if err := parseArgs(); err != nil {
return err
}
for _, root := range paths {
if err := os.MkdirAll(root, 0755); err != nil {
return err
}
err := randomfiles.WriteRandomFiles(root, 1, &opts)
if err != nil {
return err
}
}
return nil
}
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
}

View File

@ -1,40 +0,0 @@
package ringreader
import (
"bytes"
"fmt"
"math/rand"
random "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random"
)
type Reader struct {
Buf []byte
}
func NewReader(bufsize int) (*Reader, error) {
buf := bytes.NewBuffer(nil)
err := random.WritePseudoRandomBytes(int64(bufsize), buf, rand.Int63())
return &Reader{Buf: buf.Bytes()}, err
}
func (r *Reader) Read(buf []byte) (n int, err error) {
ibufl := len(r.Buf)
left := len(buf)
copied := 0
for copied < left {
pos1 := rand.Intn(len(r.Buf))
pos2 := pos1 + left
if pos2 > ibufl {
pos2 = ibufl
}
copied += copy(buf[copied:], r.Buf[pos1:pos2])
}
if copied != left {
err := fmt.Errorf("copied a different ammount: %d != %d", copied, left)
panic(err.Error())
}
return copied, nil
}

View File

@ -1,22 +0,0 @@
package ringreader
import (
"testing"
)
func TestRingReader(t *testing.T) {
r, _ := NewReader(256)
t.Log("buffer:", r.Buf)
for i := 1; i < 1048576; i = i * 2 {
buf := make([]byte, i)
n, err := r.Read(buf)
if err != nil {
t.Error(err)
}
if n != len(buf) {
t.Error("did not read %d bytes", n)
}
t.Log("read:", buf)
}
}

View File

@ -1,12 +0,0 @@
language: go
go:
- 1.3
- release
- tip
script:
- go test -race -cpu=5 -v ./...
- cd random && go build
env: TEST_VERBOSE=1

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2014 Juan Batiz-Benet
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.

View File

@ -1,29 +0,0 @@
# go-random outputs randomness
This is a unix util that outputs randomness.
It is a thin wrapper around `crypto/rand`.
It aims to be portable (though it may not yet be).
### Install
```sh
go install github.com/jbenet/go-random/random
```
(The extra /random is there because go get is stupidly too proscriptive about
package/repository names and I don't yet know how to change the default binary
output name)
### Usage:
```
> random
Usage: random <int>
Print <int> random bytes (from Go's crypto/rand)
> random 6
2q<EFBFBD><EFBFBD><EFBFBD>#
```
### License
MIT

View File

@ -1,47 +0,0 @@
package random
import (
"bytes"
randcrypto "crypto/rand"
"io"
randmath "math/rand"
)
func WriteRandomBytes(count int64, w io.Writer) error {
r := &io.LimitedReader{R: randcrypto.Reader, N: count}
_, err := io.Copy(w, r)
return err
}
func WritePseudoRandomBytes(count int64, w io.Writer, seed int64) error {
randmath.Seed(seed)
// Configurable buffer size
bufsize := int64(1024 * 1024 * 4)
b := make([]byte, bufsize)
for count > 0 {
if bufsize > count {
bufsize = count
b = b[:bufsize]
}
var n uint32
for i := int64(0); i < bufsize; {
n = randmath.Uint32()
for j := 0; j < 4 && i < bufsize; j++ {
b[i] = byte(n & 0xff)
n >>= 8
i++
}
}
count = count - bufsize
r := bytes.NewReader(b)
_, err := io.Copy(w, r)
if err != nil {
return err
}
}
return nil
}

View File

@ -1 +0,0 @@
random

View File

@ -1,49 +0,0 @@
package main
import (
"fmt"
"os"
"strconv"
random "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random"
"gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
)
func main() {
l := len(os.Args)
if l != 2 && l != 3 {
usageError()
}
countuint64, err := humanize.ParseBytes(os.Args[1])
if err != nil {
usageError()
}
count := int64(countuint64)
if l == 2 {
err = random.WriteRandomBytes(count, os.Stdout)
} else {
seed, err2 := strconv.ParseInt(os.Args[2], 10, 64)
if err2 != nil {
usageError()
}
err = random.WritePseudoRandomBytes(count, os.Stdout, seed)
}
if err != nil {
die(err)
}
}
func usageError() {
fmt.Fprintf(os.Stderr, "Usage: %s <count> [<seed>]\n", os.Args[0])
fmt.Fprintf(os.Stderr, "If <seed> is given, output <count> pseudo random bytes made from <seed> (from Go's math/rand)\n")
fmt.Fprintf(os.Stderr, "Otherwise, output <count> random bytes (from Go's crypto/rand)\n")
os.Exit(-1)
}
func die(err error) {
fmt.Fprintf(os.Stderr, "Error: %v", err)
os.Exit(-1)
}

View File

@ -1,96 +0,0 @@
package random
import (
"bytes"
"io/ioutil"
"testing"
"time"
)
func TestPseudoRandom(t *testing.T) {
var testCases = []int{
1024,
187654,
1048576,
4932132,
}
for _, size := range testCases {
var buf bytes.Buffer
err := WritePseudoRandomBytes(int64(size), &buf, int64(time.Now().UnixNano()))
if err != nil {
t.Fatal(err)
}
if buf.Len() != size {
t.Fatal("buffer not of the right size: %d != %d", buf.Len(), size)
}
}
}
func TestPseudoRandomSeed(t *testing.T) {
var first []byte
var size = int64(1024 * 4)
seed := time.Now().UnixNano()
for i := 0; i < 100; i++ {
var bufs bytes.Buffer
var bufr bytes.Buffer
if err := WritePseudoRandomBytes(size, &bufs, seed); err != nil {
t.Fatal(err)
}
if err := WritePseudoRandomBytes(size, &bufr, time.Now().UnixNano()); err != nil {
t.Fatal(err)
}
if bufs.Len() != int(size) {
t.Fatal("buffer not of the right size: %d != %d", bufs.Len(), size)
}
if bufr.Len() != int(size) {
t.Fatal("buffer not of the right size: %d != %d", bufr.Len(), size)
}
if first == nil {
first = bufs.Bytes()
} else if !bytes.Equal(first, bufs.Bytes()) {
t.Fatal("seeded constructed different bytes")
}
if bytes.Equal(first, bufr.Bytes()) {
t.Fatal("non-seeded constructed same bytes")
}
}
}
func TestCryptoRandom(t *testing.T) {
var testCases = []int{
1024,
187654,
1048576,
}
for _, size := range testCases {
var buf bytes.Buffer
err := WriteRandomBytes(int64(size), &buf)
if err != nil {
t.Fatal(err)
}
if buf.Len() != size {
t.Fatal("buffer not of the right size: %d != %d", buf.Len(), size)
}
}
}
func BenchmarkCryptoRandom(b *testing.B) {
WriteRandomBytes(int64(b.N), ioutil.Discard)
}
func BenchmarkPseudoRandom(b *testing.B) {
WritePseudoRandomBytes(int64(b.N), ioutil.Discard, time.Now().UnixNano())
}

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2013 Mitchell Hashimoto
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.

View File

@ -1,14 +0,0 @@
# go-homedir
This is a Go library for detecting the user's home directory without
the use of cgo, so the library can be used in cross-compilation environments.
Usage is incredibly simple, just call `homedir.Dir()` to get the home directory
for a user, and `homedir.Expand()` to expand the `~` in a path to the home
directory.
**Why not just use `os/user`?** The built-in `os/user` package requires
cgo on Darwin systems. This means that any Go code that uses that package
cannot cross compile. But 99% of the time the use for `os/user` is just to
retrieve the home directory, which we can do for the current user without
cgo. This library does that, enabling cross-compilation.

View File

@ -1,84 +0,0 @@
package homedir
import (
"bytes"
"errors"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
)
// Dir returns the home directory for the executing user.
//
// This uses an OS-specific method for discovering the home directory.
// An error is returned if a home directory cannot be detected.
func Dir() (string, error) {
if runtime.GOOS == "windows" {
return dirWindows()
}
// Unix-like system, so just assume Unix
return dirUnix()
}
// Expand expands the path to include the home directory if the path
// is prefixed with `~`. If it isn't prefixed with `~`, the path is
// returned as-is.
func Expand(path string) (string, error) {
if len(path) == 0 {
return path, nil
}
if path[0] != '~' {
return path, nil
}
if len(path) > 1 && path[1] != '/' && path[1] != '\\' {
return "", errors.New("cannot expand user-specific home dir")
}
dir, err := Dir()
if err != nil {
return "", err
}
return filepath.Join(dir, path[1:]), nil
}
func dirUnix() (string, error) {
// First prefer the HOME environmental variable
if home := os.Getenv("HOME"); home != "" {
return home, nil
}
// If that fails, try the shell
var stdout bytes.Buffer
cmd := exec.Command("sh", "-c", "eval echo ~$USER")
cmd.Stdout = &stdout
if err := cmd.Run(); err != nil {
return "", err
}
result := strings.TrimSpace(stdout.String())
if result == "" {
return "", errors.New("blank output when reading home directory")
}
return result, nil
}
func dirWindows() (string, error) {
drive := os.Getenv("HOMEDRIVE")
path := os.Getenv("HOMEPATH")
home := drive + path
if drive == "" || path == "" {
home = os.Getenv("USERPROFILE")
}
if home == "" {
return "", errors.New("HOMEDRIVE, HOMEPATH, and USERPROFILE are blank")
}
return home, nil
}

View File

@ -1,98 +0,0 @@
package homedir
import (
"fmt"
"os"
"os/user"
"testing"
)
func patchEnv(key, value string) func() {
bck := os.Getenv(key)
deferFunc := func() {
os.Setenv(key, bck)
}
os.Setenv(key, value)
return deferFunc
}
func TestDir(t *testing.T) {
u, err := user.Current()
if err != nil {
t.Fatalf("err: %s", err)
}
dir, err := Dir()
if err != nil {
t.Fatalf("err: %s", err)
}
if u.HomeDir != dir {
t.Fatalf("%#v != %#v", u.HomeDir, dir)
}
}
func TestExpand(t *testing.T) {
u, err := user.Current()
if err != nil {
t.Fatalf("err: %s", err)
}
cases := []struct {
Input string
Output string
Err bool
}{
{
"/foo",
"/foo",
false,
},
{
"~/foo",
fmt.Sprintf("%s/foo", u.HomeDir),
false,
},
{
"",
"",
false,
},
{
"~",
u.HomeDir,
false,
},
{
"~foo/foo",
"",
true,
},
}
for _, tc := range cases {
actual, err := Expand(tc.Input)
if (err != nil) != tc.Err {
t.Fatalf("Input: %#v\n\nErr: %s", tc.Input, err)
}
if actual != tc.Output {
t.Fatalf("Input: %#v\n\nOutput: %#v", tc.Input, actual)
}
}
defer patchEnv("HOME", "/custom/path/")()
expected := "/custom/path/foo/bar"
actual, err := Expand("~/foo/bar")
if err != nil {
t.Errorf("No error is expected, got: %v", err)
} else if actual != "/custom/path/foo/bar" {
t.Errorf("Expected: %v; actual: %v", expected, actual)
}
}

View File

@ -1,166 +0,0 @@
package levenshtein
import (
"fmt"
"os"
)
type EditOperation int
const (
Ins = iota
Del
Sub
Match
)
type EditScript []EditOperation
type MatchFunction func(rune, rune) bool
type Options struct {
InsCost int
DelCost int
SubCost int
Matches MatchFunction
}
// DefaultOptions is the default options: insertion cost is 1, deletion cost is
// 1, substitution cost is 2, and two runes match iff they are the same.
var DefaultOptions Options = Options{
InsCost: 1,
DelCost: 1,
SubCost: 2,
Matches: func(sourceCharacter rune, targetCharacter rune) bool {
return sourceCharacter == targetCharacter
},
}
func (operation EditOperation) String() string {
if operation == Match {
return "match"
} else if operation == Ins {
return "ins"
} else if operation == Sub {
return "sub"
}
return "del"
}
// DistanceForStrings returns the edit distance between source and target.
func DistanceForStrings(source []rune, target []rune, op Options) int {
return DistanceForMatrix(MatrixForStrings(source, target, op))
}
// DistanceForMatrix reads the edit distance off the given Levenshtein matrix.
func DistanceForMatrix(matrix [][]int) int {
return matrix[len(matrix)-1][len(matrix[0])-1]
}
// MatrixForStrings generates a 2-D array representing the dynamic programming
// table used by the Levenshtein algorithm, as described e.g. here:
// http://www.let.rug.nl/kleiweg/lev/
// The reason for putting the creation of the table into a separate function is
// that it cannot only be used for reading of the edit distance between two
// strings, but also e.g. to backtrace an edit script that provides an
// alignment between the characters of both strings.
func MatrixForStrings(source []rune, target []rune, op Options) [][]int {
// Make a 2-D matrix. Rows correspond to prefixes of source, columns to
// prefixes of target. Cells will contain edit distances.
// Cf. http://www.let.rug.nl/~kleiweg/lev/levenshtein.html
height := len(source) + 1
width := len(target) + 1
matrix := make([][]int, height)
// Initialize trivial distances (from/to empty string). That is, fill
// the left column and the top row with row/column indices.
for i := 0; i < height; i++ {
matrix[i] = make([]int, width)
matrix[i][0] = i
}
for j := 1; j < width; j++ {
matrix[0][j] = j
}
// Fill in the remaining cells: for each prefix pair, choose the
// (edit history, operation) pair with the lowest cost.
for i := 1; i < height; i++ {
for j := 1; j < width; j++ {
delCost := matrix[i-1][j] + op.DelCost
matchSubCost := matrix[i-1][j-1]
if !op.Matches(source[i-1], target[j-1]) {
matchSubCost += op.SubCost
}
insCost := matrix[i][j-1] + op.InsCost
matrix[i][j] = min(delCost, min(matchSubCost,
insCost))
}
}
//LogMatrix(source, target, matrix)
return matrix
}
// EditScriptForStrings returns an optimal edit script to turn source into
// target.
func EditScriptForStrings(source []rune, target []rune, op Options) EditScript {
return backtrace(len(source), len(target),
MatrixForStrings(source, target, op), op)
}
// EditScriptForMatrix returns an optimal edit script based on the given
// Levenshtein matrix.
func EditScriptForMatrix(matrix [][]int, op Options) EditScript {
return backtrace(len(matrix[0])-1, len(matrix)-1, matrix, op)
}
// LogMatrix outputs a visual representation of the given matrix for the given
// strings on os.Stderr.
func LogMatrix(source []rune, target []rune, matrix [][]int) {
fmt.Fprintf(os.Stderr, " ")
for _, targetRune := range target {
fmt.Fprintf(os.Stderr, " %c", targetRune)
}
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, " %2d", matrix[0][0])
for j, _ := range target {
fmt.Fprintf(os.Stderr, " %2d", matrix[0][j+1])
}
fmt.Fprintf(os.Stderr, "\n")
for i, sourceRune := range source {
fmt.Fprintf(os.Stderr, "%c %2d", sourceRune, matrix[i+1][0])
for j, _ := range target {
fmt.Fprintf(os.Stderr, " %2d", matrix[i+1][j+1])
}
fmt.Fprintf(os.Stderr, "\n")
}
}
func backtrace(i int, j int, matrix [][]int, op Options) EditScript {
if i > 0 && matrix[i-1][j]+op.DelCost == matrix[i][j] {
return append(backtrace(i-1, j, matrix, op), Del)
}
if j > 0 && matrix[i][j-1]+op.InsCost == matrix[i][j] {
return append(backtrace(i, j-1, matrix, op), Ins)
}
if i > 0 && j > 0 && matrix[i-1][j-1]+op.SubCost == matrix[i][j] {
return append(backtrace(i-1, j-1, matrix, op), Sub)
}
if i > 0 && j > 0 && matrix[i-1][j-1] == matrix[i][j] {
return append(backtrace(i-1, j-1, matrix, op), Match)
}
return []EditOperation{}
}
func min(a int, b int) int {
if b < a {
return b
}
return a
}
func max(a int, b int) int {
if b > a {
return b
}
return a
}

View File

@ -1,46 +0,0 @@
package levenshtein_test
import (
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/texttheater/golang-levenshtein/levenshtein"
"testing"
)
var testCases = []struct {
source string
target string
distance int
}{
{"", "a", 1},
{"a", "aa", 1},
{"a", "aaa", 2},
{"", "", 0},
{"a", "b", 2},
{"aaa", "aba", 2},
{"aaa", "ab", 3},
{"a", "a", 0},
{"ab", "ab", 0},
{"a", "", 1},
{"aa", "a", 1},
{"aaa", "a", 2},
}
func TestLevenshtein(t *testing.T) {
for _, testCase := range testCases {
distance := levenshtein.DistanceForStrings(
[]rune(testCase.source),
[]rune(testCase.target),
levenshtein.DefaultOptions)
if distance != testCase.distance {
t.Log(
"Distance between",
testCase.source,
"and",
testCase.target,
"computed as",
distance,
", should be",
testCase.distance)
t.Fail()
}
}
}

View File

@ -42,7 +42,7 @@ CLEAN += $(COVER_BIN_$(d))
$(COVER_BIN_$(d)): GOTAGS += testrunmain
$(COVER_BIN_$(d)): $(d) $$(DEPS_GO) ALWAYS
$(eval TMP_PKGS := $(shell $(GOCC) list -f '{{range .Deps}}{{.}} {{end}}' $(go-flags-with-tags) ./cmd/ipfs | sed 's/ /\n/g' | grep ipfs/go-ipfs | grep -v ipfs/go-ipfs/Godeps) $(call go-pkg-name,$<))
$(eval TMP_PKGS := $(shell $(GOCC) list -f '{{range .Deps}}{{.}} {{end}}' $(go-flags-with-tags) ./cmd/ipfs | sed 's/ /\n/g' | grep ipfs/go-ipfs) $(call go-pkg-name,$<))
$(eval TMP_LIST := $(call join-with,$(comma),$(TMP_PKGS)))
@echo $(GOCC) test $@ -c -covermode atomic -coverpkg ... $(go-flags-with-tags) ./$(@D) # for info
@$(GOCC) test -o $@ -c -covermode atomic -coverpkg $(TMP_LIST) $(go-flags-with-tags) ./$(@D) 2>&1 | (grep -v 'warning: no packages being tested' || true)

View File

@ -14,11 +14,10 @@ import (
corehttp "github.com/ipfs/go-ipfs/core/corehttp"
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
config "gx/ipfs/QmYVqYJTVjetcf1guieEgWpK1PZtHPytP624vKzTF1P3r2/go-ipfs-config"
homedir "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
process "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
config "gx/ipfs/QmYVqYJTVjetcf1guieEgWpK1PZtHPytP624vKzTF1P3r2/go-ipfs-config"
homedir "gx/ipfs/QmdcULN1WCzgoQmcCaUAmEhwcxHYsDrbZ2LvRJKCL8dMrK/go-homedir"
fsnotify "gx/ipfs/QmfNjggF4Pt6erqg3NDafD3MdvDHk1qqCVr8pL5hnPucS8/fsnotify"
)

View File

@ -10,13 +10,13 @@ endif
.PHONY: $(d)/coverage_deps
# unit tests coverage
UTESTS_$(d) := $(shell go list -f '{{if (len .TestGoFiles)}}{{.ImportPath}}{{end}}' $(go-flags-with-tags) ./... | grep -v go-ipfs/vendor | grep -v go-ipfs/Godeps)
UTESTS_$(d) := $(shell go list -f '{{if (len .TestGoFiles)}}{{.ImportPath}}{{end}}' $(go-flags-with-tags) ./...)
UCOVER_$(d) := $(addsuffix .coverprofile,$(addprefix $(d)/unitcover/, $(subst /,_,$(UTESTS_$(d)))))
$(UCOVER_$(d)): $(d)/coverage_deps ALWAYS
$(eval TMP_PKG := $(subst _,/,$(basename $(@F))))
$(eval TMP_DEPS := $(shell go list -f '{{range .Deps}}{{.}} {{end}}' $(go-flags-with-tags) $(TMP_PKG) | sed 's/ /\n/g' | grep ipfs/go-ipfs | grep -v ipfs/go-ipfs/Godeps) $(TMP_PKG))
$(eval TMP_DEPS := $(shell go list -f '{{range .Deps}}{{.}} {{end}}' $(go-flags-with-tags) $(TMP_PKG) | sed 's/ /\n/g' | grep ipfs/go-ipfs) $(TMP_PKG))
$(eval TMP_DEPS_LIST := $(call join-with,$(comma),$(TMP_DEPS)))
go test $(go-flags-with-tags) $(GOTFLAGS) -covermode=atomic -coverpkg=$(TMP_DEPS_LIST) -coverprofile=$@ $(TMP_PKG)

View File

@ -19,7 +19,7 @@ CHECK_GO :=
go-pkg-name=$(shell $(GOCC) list $(go-tags) github.com/ipfs/go-ipfs/$(1))
go-main-name=$(notdir $(call go-pkg-name,$(1)))$(?exe)
go-curr-pkg-tgt=$(d)/$(call go-main-name,$(d))
go-pkgs-novendor=$(shell $(GOCC) list github.com/ipfs/go-ipfs/... | grep -v /Godeps/)
go-pkgs=$(shell $(GOCC) list github.com/ipfs/go-ipfs/...)
go-tags=$(if $(GOTAGS), -tags="$(call join-with,$(space),$(GOTAGS))")
go-flags-with-tags=$(GOFLAGS)$(go-tags)
@ -55,7 +55,7 @@ TEST_GO += test_go_fmt
test_go_megacheck:
@$(GOCC) get honnef.co/go/tools/cmd/megacheck
@for pkg in $(go-pkgs-novendor); do megacheck "$$pkg"; done
@for pkg in $(go-pkgs); do megacheck "$$pkg"; done
.PHONY: megacheck
test_go: $(TEST_GO)

View File

@ -551,6 +551,23 @@
"hash": "QmRgFWjY1idcimoGvSAzNenfptnciZnPHuW3P2yq9VgaqA",
"name": "go-libp2p-quic-transport",
"version": "0.2.4"
},
{
"author": "mitchellh",
"hash": "QmdcULN1WCzgoQmcCaUAmEhwcxHYsDrbZ2LvRJKCL8dMrK",
"name": "go-homedir",
"version": "1.0.0"
},
{
"hash": "QmSJ9n2s9NUoA9D849W5jj5SJ94nMcZpj1jCgQJieiNqSt",
"name": "go-random",
"version": "1.0.0"
},
{
"author": "jbenet",
"hash": "QmbyJLe6SdVR5VLjtcoLdKhUuV4RT9a1FxX28zaWnY34d8",
"name": "go-random-files",
"version": "1.0.0"
}
],
"gxVersion": "0.10.0",

View File

@ -1,6 +1,3 @@
package pb
//go:generate protoc --gogo_out=. header.proto
// kludge to get vendoring right in protobuf output
//go:generate sed -i s,github.com/,github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/,g header.pb.go

View File

@ -18,8 +18,6 @@ import (
mfsr "github.com/ipfs/go-ipfs/repo/fsrepo/migrations"
dir "github.com/ipfs/go-ipfs/thirdparty/dir"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
util "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
logging "gx/ipfs/QmRREK2CAZ5Re2Bd9zZFG6FeYDppUWt5cMgsoUEp3ktgSr/go-log"
ds "gx/ipfs/QmSpg1CvpXQQow5ernt1gNBXaXV6yxyNqi7XoeerWfzB5w/go-datastore"
@ -28,6 +26,7 @@ import (
ma "gx/ipfs/QmYmsdtJ3HsodkePE3eU3TsCaP2YvPZJ4LoXnNkDE5Tpt7/go-multiaddr"
lockfile "gx/ipfs/QmZzgxSj8QpR58KmdeNj97eD66X6xeDAFNjpP2xTY9oKeQ/go-fs-lock"
measure "gx/ipfs/QmcUJcDvigNo8epy9STuJRuMUpjz6UxH5BSgMNSJAfzTem/go-ds-measure"
homedir "gx/ipfs/QmdcULN1WCzgoQmcCaUAmEhwcxHYsDrbZ2LvRJKCL8dMrK/go-homedir"
)
// LockFile is the filename of the repo lock, relative to config dir

View File

@ -3,9 +3,8 @@ package fsrepo
import (
"os"
homedir "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
config "gx/ipfs/QmYVqYJTVjetcf1guieEgWpK1PZtHPytP624vKzTF1P3r2/go-ipfs-config"
homedir "gx/ipfs/QmdcULN1WCzgoQmcCaUAmEhwcxHYsDrbZ2LvRJKCL8dMrK/go-homedir"
)
// BestKnownPath returns the best known fsrepo path. If the ENV override is

View File

@ -1,4 +1,3 @@
RANDOMSRC = ../../Godeps/_workspace/src/github.com/jbenet/go-random
IMAGE_NAME = ipfs-test-latest
IPFS_ROOT = ../..
@ -20,7 +19,8 @@ data/filerand: bin/random
./bin/random 50000000 > ./data/filerand
bin/random: $(RANDOMSRC)/**/*.go
go build -o ./bin/random $(RANDOMSRC)/random
go get github.com/jbenet/go-random
go build -o ./bin/random github.com/jbenet/go-random/random
# just build it every time... this part isn't
# even the lengthy part, and it decreases pain.

View File

@ -10,9 +10,9 @@ import (
"path"
"testing"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random"
"github.com/ipfs/go-ipfs/thirdparty/unit"
random "gx/ipfs/QmSJ9n2s9NUoA9D849W5jj5SJ94nMcZpj1jCgQJieiNqSt/go-random"
config "gx/ipfs/QmYVqYJTVjetcf1guieEgWpK1PZtHPytP624vKzTF1P3r2/go-ipfs-config"
)

View File

@ -9,9 +9,9 @@ import (
"path"
"testing"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random"
"github.com/ipfs/go-ipfs/thirdparty/unit"
random "gx/ipfs/QmSJ9n2s9NUoA9D849W5jj5SJ94nMcZpj1jCgQJieiNqSt/go-random"
config "gx/ipfs/QmYVqYJTVjetcf1guieEgWpK1PZtHPytP624vKzTF1P3r2/go-ipfs-config"
)

View File

@ -2,14 +2,6 @@ include mk/header.mk
TGTS_$(d) :=
$(d)/random: Godeps/_workspace/src/github.com/jbenet/go-random/random
$(go-build)
TGTS_$(d) += $(d)/random
$(d)/random-files: Godeps/_workspace/src/github.com/jbenet/go-random-files/random-files
$(go-build)
TGTS_$(d) += $(d)/random-files
$(d)/pollEndpoint: thirdparty/pollEndpoint
$(go-build)
TGTS_$(d) += $(d)/pollEndpoint
@ -44,6 +36,16 @@ $(d)/cid-fmt:
go build -i $(go-flags-with-tags) -o "$@" "gx/ipfs/$(shell gx deps find go-cidutil)/go-cidutil/cid-fmt"
TGTS_$(d) += $(d)/cid-fmt
# random is also special
$(d)/random:
go build -i $(go-flags-with-tags) -o "$@" "gx/ipfs/$(shell gx deps find go-random)/go-random/random"
TGTS_$(d) += $(d)/random
# random-files is also special
$(d)/random-files:
go build -i $(go-flags-with-tags) -o "$@" "gx/ipfs/$(shell gx deps find go-random-files)/go-random-files/random-files"
TGTS_$(d) += $(d)/random-files
$(TGTS_$(d)): $$(DEPS_GO)

View File

@ -5,7 +5,7 @@
verify_gofmt() {
GOFMT="gofmt -s"
cd "$(git rev-parse --show-toplevel)"
bad_files=$($GOFMT -l . | grep -v Godeps)
bad_files=$($GOFMT -l .)
cd -
if [[ -n $bad_files ]]; then
echo "You have to run '$GOFMT' on these files:"

View File

@ -11,8 +11,6 @@ import (
"testing"
"time"
random "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random"
"github.com/ipfs/go-ipfs/core"
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
mock "github.com/ipfs/go-ipfs/core/mock"
@ -20,6 +18,7 @@ import (
testutil "gx/ipfs/QmRNhSdqzMcuRxX9A1egBeQ3BhDTguDV5HPwi8wRykkPU8/go-testutil"
logging "gx/ipfs/QmRREK2CAZ5Re2Bd9zZFG6FeYDppUWt5cMgsoUEp3ktgSr/go-log"
random "gx/ipfs/QmSJ9n2s9NUoA9D849W5jj5SJ94nMcZpj1jCgQJieiNqSt/go-random"
mocknet "gx/ipfs/QmUEqyXr97aUbNmQADHYNknjwjjdVpJXEt1UZXmSG81EV4/go-libp2p/p2p/net/mock"
pstore "gx/ipfs/Qmda4cPRvSRyox3SqgJN6DfSZGU5TtHufPTp9uXjFj71X6/go-libp2p-peerstore"
)

View File

@ -1,9 +0,0 @@
// package randomdep is here to introduce a dependency in random for godep to
// function properly. this way we can keep go-random vendored and not
// accidentally break our tests when we change it.
package randomdep
import (
_ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random"
_ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random-files"
)