Skip to content

Commit

Permalink
Encrypted folder change name
Browse files Browse the repository at this point in the history
  • Loading branch information
hauleIT committed Mar 5, 2021
1 parent 7500bd0 commit 6b89971
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 2 deletions.
1 change: 1 addition & 0 deletions Encrypted/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test create new allocation
5 changes: 5 additions & 0 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ var deleteCmd = &cobra.Command{
}
remotepath := cmd.Flag("remotepath").Value.String()

if remotepath == "/Encrypted" {
PrintError("Error: Can not delete Encrypted Folder")
os.Exit(1)
}

statsMap, err := allocationObj.GetFileStats(remotepath)
if err != nil {
PrintError("Error in getting information about the object." + err.Error())
Expand Down
34 changes: 34 additions & 0 deletions cmd/newallocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import (
"log"
"math"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"time"

"github.com/0chain/gosdk/zboxcore/fileref"
"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/0chain/gosdk/zcncore"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -137,6 +140,37 @@ var newallocationCmd = &cobra.Command{
}
log.Print("Allocation created: ", allocationID)
storeAllocation(allocationID)
allocationObj, err := sdk.GetAllocation(allocationID)
if err != nil {
PrintError("Error fetching the allocation.", err)
os.Exit(1)
}
localpath, _ := filepath.Abs("../zboxcli/Encrypted/test.txt") // path from the working directory

remotepath := "/Encrypted/test.txt"
encrypt := true
wg := &sync.WaitGroup{}
statusBar := &StatusBar{wg: wg}
wg.Add(1)
var attrs fileref.Attributes
if encrypt {
err = allocationObj.EncryptAndUploadFile(localpath, remotepath, attrs, statusBar)
} else {
err = allocationObj.UploadFile(localpath, remotepath, attrs, statusBar)
}
if err != nil {
PrintError("Upload failed.", err)
os.Exit(1)
}
wg.Wait()
if !statusBar.success {
os.Exit(1)
}
err = allocationObj.DeleteFile(remotepath)
if err != nil {
PrintError("Delete failed.", err.Error())
os.Exit(1)
}
}
return
},
Expand Down
7 changes: 6 additions & 1 deletion cmd/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ var renameCmd = &cobra.Command{
os.Exit(1)
}
}

if !isFile {
if remotepath == "/Encrypted" {
PrintError("Error: Can not rename Encrypted Folder")
os.Exit(1)
}
}
err = allocationObj.RenameObject(remotepath, destname)
if err != nil {
PrintError(err.Error())
Expand Down
5 changes: 5 additions & 0 deletions cmd/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/0chain/gosdk/zboxcore/fileref"
"github.com/0chain/gosdk/zboxcore/sdk"
Expand Down Expand Up @@ -48,6 +49,10 @@ var shareCmd = &cobra.Command{
}
if !isFile {
refType = fileref.DIRECTORY
if strings.HasPrefix(remotepath, "/Encrypted") {
PrintError("Error: Can not share folder (inside) Encrypted Folder")
os.Exit(1)
}
}

var fileName string
Expand Down
4 changes: 4 additions & 0 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ var updateCmd = &cobra.Command{
encrypt, _ := cmd.Flags().GetBool("encrypt")
commit, _ := cmd.Flags().GetBool("commit")

if remotepath == "/Encrypted" {
PrintError("Error: can not update Encrypted Folder")
os.Exit(1)
}
// get original file attributes
var attrs = getRemoteFileAttributes(allocationObj, remotepath)

Expand Down
5 changes: 4 additions & 1 deletion cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"log"
"os"
"strings"
"sync"

"github.com/0chain/gosdk/core/common"
Expand Down Expand Up @@ -47,7 +48,9 @@ var uploadCmd = &cobra.Command{
wg := &sync.WaitGroup{}
statusBar := &StatusBar{wg: wg}
wg.Add(1)

if strings.HasPrefix(remotepath, "/Encrypted") {
encrypt = true
}
var attrs fileref.Attributes
if fflags.Changed("attr-who-pays-for-reads") {
var (
Expand Down

0 comments on commit 6b89971

Please sign in to comment.