-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from gagliardetto/cli-v0
Fix fallocate, add `version` cmd, add cross-compilation
- Loading branch information
Showing
12 changed files
with
173 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"runtime/debug" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func newCmd_Version() *cli.Command { | ||
return &cli.Command{ | ||
Name: "version", | ||
Description: "Print version information", | ||
Before: func(c *cli.Context) error { | ||
return nil | ||
}, | ||
Flags: []cli.Flag{}, | ||
Action: func(c *cli.Context) error { | ||
fmt.Println("YELLOWSTONE FAITHFUL CLI") | ||
fmt.Printf("Tag/Branch: %s\n", GitTag) | ||
fmt.Printf("Commit: %s\n", GitCommit) | ||
if info, ok := debug.ReadBuildInfo(); ok { | ||
fmt.Printf("More info:\n") | ||
for _, setting := range info.Settings { | ||
if isAnyOf(setting.Key, | ||
"-compiler", | ||
"GOARCH", | ||
"GOOS", | ||
"GOAMD64", | ||
"vcs", | ||
"vcs.revision", | ||
"vcs.time", | ||
"vcs.modified", | ||
) { | ||
fmt.Printf(" %s: %s\n", setting.Key, setting.Value) | ||
} | ||
} | ||
} | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
var ( | ||
GitCommit string | ||
GitTag string | ||
) | ||
|
||
func isAnyOf(s string, anyOf ...string) bool { | ||
for _, v := range anyOf { | ||
if s == v { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package compactindex | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func fake_fallocate(f *os.File, offset int64, size int64) error { | ||
const blockSize = 4096 | ||
var zero [blockSize]byte | ||
|
||
for size > 0 { | ||
step := size | ||
if step > blockSize { | ||
step = blockSize | ||
} | ||
|
||
if _, err := f.Write(zero[:step]); err != nil { | ||
return fmt.Errorf("failure while generic fallocate: %w", err) | ||
} | ||
|
||
offset += step | ||
size -= step | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
//go:build linux | ||
|
||
package compactindex | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"syscall" | ||
) | ||
|
||
func fallocate(f *os.File, offset int64, size int64) error { | ||
return syscall.Fallocate(int(f.Fd()), 0, offset, size) | ||
err := syscall.Fallocate(int(f.Fd()), 0, offset, size) | ||
if err != nil { | ||
return fmt.Errorf("failure while linux fallocate: %w", err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package compactindex36 | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func fake_fallocate(f *os.File, offset int64, size int64) error { | ||
const blockSize = 4096 | ||
var zero [blockSize]byte | ||
|
||
for size > 0 { | ||
step := size | ||
if step > blockSize { | ||
step = blockSize | ||
} | ||
|
||
if _, err := f.Write(zero[:step]); err != nil { | ||
return fmt.Errorf("failure while generic fallocate: %w", err) | ||
} | ||
|
||
offset += step | ||
size -= step | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,11 @@ | ||
//go:build !linux | ||
|
||
package compactindex | ||
package compactindex36 | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
func fallocate(f *os.File, offset int64, size int64) error { | ||
const blockSize = 4096 | ||
var zero [blockSize]byte | ||
|
||
for size > 0 { | ||
step := size | ||
if step > blockSize { | ||
step = blockSize | ||
} | ||
|
||
if _, err := f.Write(zero[:step]); err != nil { | ||
return err | ||
} | ||
|
||
offset += step | ||
size -= step | ||
} | ||
|
||
return nil | ||
return fake_fallocate(f, offset, size) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
//go:build linux | ||
|
||
package compactindex36 | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"syscall" | ||
) | ||
|
||
func fallocate(f *os.File, offset int64, size int64) error { | ||
return syscall.Fallocate(int(f.Fd()), 0, offset, size) | ||
err := syscall.Fallocate(int(f.Fd()), 0, offset, size) | ||
if err != nil { | ||
return fmt.Errorf("failure while linux fallocate: %w", err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters