Skip to content

Commit

Permalink
adding misc file
Browse files Browse the repository at this point in the history
  • Loading branch information
dmnyu committed Mar 4, 2024
1 parent 387a9dd commit cc0a8bb
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 17 deletions.
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
tidy:
go mod tidy

build:
go build -o build/go-bagit main/main.go

install:
sudo cp build/go-bagit /usr/local/go/bin/

test:
gotest -v

clean:
rm -rf build/go-bagit

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# go-bagit
Early Go implementation of the bagit specification

## Unsupported features
* Windows support
* creation of bags with multiple algorithm manifests
* fetch.txt / holey bags
* tag files other than bagit.txt and bag-info.txt

## Building From Source
`go build -o go-bagit main/main.go`

Expand Down
10 changes: 5 additions & 5 deletions bag.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,18 @@ func CreateBag(inputDir string, algorithm string, numProcesses int) (Bag, error)
return Bag{}, err
}

//Generate bagit.txt
//Generate and serialize bagit.txt
log.Println("- INFO - Creating bagit.txt")
bagit := CreateBagit()

//serialize bagit
bagitBytes := bagit.GetTagSetAsByteSlice()
if err = os.WriteFile(filepath.Join(inputDir, bagit.Filename), bagitBytes, 0755); err != nil {
return Bag{}, err
}
bagit.Path = inputDir //this can be deleted

bagit.Path = inputDir
//generate and serialize bag-info.txt
log.Println("- INFO - Creating bag-info.txt")

//get the oxum
oxum, err := CalculateOxum(inputDir)
if err != nil {
Expand All @@ -274,7 +274,7 @@ func CreateBag(inputDir string, algorithm string, numProcesses int) (Bag, error)
return bag, err
}

// Adds a file to the bag root and registers it in the tag manifest file
// Adds a file to the bag root and registers it in the tagmanifest file
func (b Bag) AddFileToBagRoot(file string) error {

//check if source file is valid
Expand Down
21 changes: 21 additions & 0 deletions cmd/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"fmt"
"runtime/debug"

"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(infoCmd)
}

var infoCmd = &cobra.Command{
Use: "info",
Run: func(cmd *cobra.Command, args []string) {
bi, _ := debug.ReadBuildInfo()
fmt.Println("Build Info\n==========")
fmt.Println(bi)
},
}
28 changes: 16 additions & 12 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,33 @@ import (
"fmt"
"os"
"path/filepath"
"runtime/debug"
"time"
)

var currentTime = time.Now()

const version = "0.2.3-alpha"

func GetSoftwareAgent() string {
const mod = "github.com/nyudlts/go-bagit"

info, ok := debug.ReadBuildInfo()
if !ok {
return fmt.Sprintf("go-bagit <https://%s>", mod)
}
//this is broken always returns "devel"
/*
info, ok := debug.ReadBuildInfo()
if !ok {
return fmt.Sprintf("go-bagit <https://%s>", mod)
}
version := "(unknown)"
for _, dep := range info.Deps {
if dep.Path == mod {
version = dep.Version
break
version := "(unknown)"
for _, dep := range info.Deps {
if dep.Path == mod {
version = dep.Version
break
}
}
}
*/

return fmt.Sprintf("go-bagit %s <https://%s>", version, mod)
return fmt.Sprintf("go-bagit (%s) <https://%s>", version, mod)
}

func getABS(path string) (string, error) {
Expand Down

0 comments on commit cc0a8bb

Please sign in to comment.