Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed how the wrapContent function creates temporary directories an… #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
34 changes: 10 additions & 24 deletions content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import (
"PGFS/global"
"context"
"fmt"
"io"
"io/ioutil"
"os"
"strconv"
"time"

files "github.com/ipfs/go-ipfs-files"
icore "github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/path"
igc "github.com/marni/goigc"
"io/ioutil"
"os"
"path/filepath"
)

/*
Expand Down Expand Up @@ -70,41 +67,30 @@ func AddContent(filePath string, node icore.CoreAPI, ctx context.Context) (strin
*/
func WrapContent(filePath string) (files.Node, string, error) {

stamp := int(time.Now().UnixNano() / int64(time.Millisecond)) // Creates unique stamp
time.Sleep(1 * time.Millisecond) // Assure uniqueness
dir := global.TempContentPath + "pkg" + strconv.Itoa(stamp) + "/" // Temp wrapper dir path
//stamp := int(time.Now().UnixNano() / int64(time.Millisecond)) // Creates unique stamp
//time.Sleep(1 * time.Millisecond) // Assure uniqueness
//dir := + "pkg" + strconv.Itoa(stamp) + "/" // Temp wrapper dir path

err := os.Mkdir(dir, 0755) // Makes temp package dir on dir path
dir, err := ioutil.TempDir(global.TempContentPath, "tmp") // Makes temp package dir on dir path
if err != nil {
return nil, dir, fmt.Errorf("failed creating wrapper package: %s", err)
}

fileIn, err := os.Open(filePath) // Opens the given file
input, err := ioutil.ReadFile(filePath) // Opens the given file
if err != nil {
return nil, dir, fmt.Errorf("failed opening given file: %s", err)
}

fileOut, err := os.Create(dir + "data.igc") // Creates a data.igc file in the package directory
err = ioutil.WriteFile(dir + "\\" + filepath.Base(filePath), input, 0755) // Copies the file into the temporary package directory
if err != nil {
fileIn.Close()
return nil, dir, fmt.Errorf("failed creating data.igc file: %s", err)
}

_, err = io.Copy(fileOut, fileIn) // Copies the file into the temporary package directory
if err != nil {
fileIn.Close() // Closes file
fileOut.Close()
return nil, dir, fmt.Errorf("failed copying file to wrapper: %s", err)
}

fileIn.Close() // Closes file
fileOut.Close()

track, err := igc.ParseLocation(filePath) // getting the location igc
fileData := fmt.Sprintf("Pilot: %s, gliderType: %s, date: %s",
track.Pilot, track.GliderType, track.Date.String())

err = ioutil.WriteFile(dir+"metadata.txt", []byte(fileData), 0755) // Creates a metadata file with the location
err = ioutil.WriteFile(dir + "\\" + "metadata.txt", []byte(fileData), 0755) // Creates a metadata file with the location

if err != nil {
return nil, dir, fmt.Errorf("failed creating metadata file: %s", err)
Expand Down
1 change: 1 addition & 0 deletions content/temp/pkg1621090887387/data.igc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is a file used for testing
1 change: 1 addition & 0 deletions content/temp/pkg1621090887387/metadata.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pilot: , gliderType: , date: 0001-01-01 00:00:00 +0000 UTC