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

feat(commit): removed commit #302

Merged
merged 4 commits into from
Sep 29, 2022
Merged
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
28 changes: 1 addition & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ zbox is a command line interface (CLI) tool to understand the capabilities of 0C
- [Repair](#repair)
- [Add collaborator](#add-collaborator)
- [Delete collaborator](#delete-collaborator)
- [Commit](#commit)
- [Sign data](#sign-data)
- [Streaming](#streaming)
- [How it works:](#how-it-works)
Expand Down Expand Up @@ -122,7 +121,6 @@ When you run the `zbox` command in terminal with no arguments, it will list all
[validator-info](#detailed-validator-information)|Get validator info
[bl-update](#update-blobber-settings)|Update blobber settings by its delegate\_wallet owner
[validator-update](#update-validator-settings)|Update validator settings by its delegate\_wallet owner
[commit](#commit)| commit file changes to chain
[collect-reward](#collect-rewards)|transfer reward tokens from a stake pool to your wallet.
[copy](#copy)|copy an object(file/folder) to another folder on blobbers
[cp-info](#challenge-pool-information)|Challenge pool information.
Expand Down Expand Up @@ -673,7 +671,6 @@ The user must be the owner of the allocation.You can request the file be encrypt
| Parameter | Required | Description | Default | Valid values |
|-------------------------|----------|------------------------------------------------------|---------|-----------------------------------------|
| allocation | yes | allocation id, sender must be allocation owner | | string |
| commit | no | save metadata to blockchain | false | boolean |
| encrypt | no | encrypt file before upload | false | boolean |
| localpath | yes | local path of the file to upload | | file path |
| remotepath | yes | remote path to upload file to, use to access file later | | string |
Expand Down Expand Up @@ -729,7 +726,6 @@ The user must be the owner of the allocation.You can request the file be encrypt
| Parameter | Required | Description | Default | Valid values |
|-------------------------|----------|------------------------------------------------------|---------|-----------------------------------------|
| allocation | yes | allocation id, sender must be allocation owner | | string |
| commit | no | save metadata to blockchain | false | boolean |
| encrypt | no | encrypt file before upload | false | boolean |
| localpath | yes | local path of segment files to download, generate and upload | | file path |
| remotepath | yes | remote path to upload file to, use to access file later | | string |
Expand All @@ -755,7 +751,6 @@ The user must be the owner of the allocation.You can request the file be encrypt
| Parameter | Required | Description | Default | Valid values |
|-------------------------|----------|------------------------------------------------------|---------|-----------------------------------------|
| allocation | yes | allocation id, sender must be allocation owner | | string |
| commit | no | save metadata to blockchain | false | boolean |
| encrypt | no | encrypt file before upload | false | boolean |
| localpath | yes | local path of segment files to download, generate and upload | | file path |
| remotepath | yes | remote path to upload file to, use to access file later | | string |
Expand Down Expand Up @@ -824,7 +819,6 @@ Use `startblock` and `endblock` to only download part of the file.
| allocation | yes | allocation id | | string |
| authticket | no | auth ticked if not owner of the allocation, use share to get auth ticket | | string |
| blockspermarker | no | download multiple blocks per marker | 10 | int |
| commit | no | save metadata to blockchain | false | boolean |
| endblock | no | download until specified block number | | int |
| localpath | yes | local path to which to download the file to | | file path |
| remotepath | yes | remote path to which the file was uploaded | | string |
Expand Down Expand Up @@ -875,7 +869,6 @@ can update a file. To add collaborators to an allocation, use
| localpath | yes | local file to upload | | file path |
| remotepath | yes | remote file to upload | | string |
| thumbnailpath | no | local fumbnail file to upload | | file path |
| commit | no | save meta data to blockchain | false | boolean |
| chunknumber | no | how many chunks should be uploaded in a http request | 1 | int |


Expand All @@ -895,7 +888,6 @@ of the application can delete a file.
|------------|----------|-------------------------------|---------|--------------|
| allocation | yes | allocation id | | string |
| remotepath | yes | remote path of file to delete | | string |
| commit | no | save meta data to blockchain | false | boolean |

<details>
<summary>delete</summary>
Expand Down Expand Up @@ -930,7 +922,7 @@ Use share command to generate an authtoken that provides authorization to the ho
if option not provided)
* --available-after Timelock for private file that makes the file available for download at certain time. 4 input formats are supported: +1h30m, +30, 1647858200 and 2022-03-21 10:21:38

`auth ticket` can be used with [download](#download), [commit](#commit) and [list](#list),
`auth ticket` can be used with [download](#download), and [list](#list),
[meta](#get-metadata) and [get_download_cost](#download-cost), but only for files in
the pre-defined remote path.

Expand Down Expand Up @@ -1106,7 +1098,6 @@ Only the owner of the allocation can copy an object.
| Parameter | Required | Description | default | Valid values |
|------------|----------|---------------------------------------------------|---------|--------------|
| allocation | yes | allocation id | | string |
| commit | no | save metadata to blockchain | false | boolean |
| remotepath | yes | remote path of object to copy | | string |
| destpath | yes | destination, an existing directory to copy object | | string |

Expand Down Expand Up @@ -1138,7 +1129,6 @@ Only the owner of the allocation can copy an object.
| Parameter | Required | Description | default | Valid values |
|------------|----------|---------------------------------------------------|---------|--------------|
| allocation | yes | allocation id | | string |
| commit | no | save metadata to blockchain | false | boolean |
| remotepath | yes | remote path of object to copy | | string |
| destpath | yes | destination, an existing directory to copy object | | string |

Expand Down Expand Up @@ -1170,7 +1160,6 @@ Only the allocation's owner can successfully run `sync`.
| Parameter | Required | Description | default | Valid values |
|-------------|----------|-----------------------------------------------------------------------------------------------|---------|--------------|
| allocation | yes | allocation id | | string |
| commit | no | commet metadata to blockchain | false | boolean |
| encryptpath | no | local directory path to be uploaded as encrypted | false | boolean |
| excludepath | no | paths to exclude from sync | | string array |
| localchache | no | local chache of remote snapshot. Used for comparsion with remote. After sync will be updated. | | string |
Expand Down Expand Up @@ -1380,7 +1369,6 @@ allocation's owner can rename a file.
| Parameter | Required | Description | default | Valid values |
|------------|----------|---------------------------------------------------|---------|--------------|
| allocation | yes | allocation id | | string |
| commit | no | save metadata to blockchain | false | boolean |
| destname | yes | new neame of the object | | string |
| remotepath | yes | remote path of object, do not use with authticket | | string |

Expand Down Expand Up @@ -1537,20 +1525,6 @@ Collaborator d477d12134c2d7ba5ab71ac8ad37f244224695ef3215be990c3215d531c5a329 re
```


#### Commit

Commit file changes to chain

| Parameter | Required | Description | Valid values |
|------------|----------|---------------------------------------------------|--------------|
| allocation | yes | allocation id | string |
| authticket | no | auth ticket for file to commit | string |
| filemeta | no | meta for commit if applicable | string |
| lookuphash | no | remote lookuphash to commit, use with authticket | string |
| newvalue | no | new value for the folder operation if applicatble | string |
| operation | yes | operation name for commit change | string |
| remotepath | no | remote path of object to commit | string |

#### Sign data

`sign-data` uses the information from your wallet to sign the input data string
Expand Down
99 changes: 0 additions & 99 deletions cmd/commit.go

This file was deleted.

30 changes: 0 additions & 30 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"os"
"sync"

"github.com/0chain/gosdk/core/transaction"
"github.com/0chain/gosdk/zboxcore/sdk"
"gopkg.in/cheggaaa/pb.v1"
)

Expand Down Expand Up @@ -52,17 +50,6 @@ func (s *StatusBar) Error(allocationID string, filePath string, op int, err erro
PrintError("Error in file operation:", errDetail)
}

func (s *StatusBar) CommitMetaCompleted(request, response string, txn *transaction.Transaction, err error) {
defer s.wg.Done()
if err != nil {
s.success = false
PrintError("Error in commitMetaTransaction." + err.Error())
} else {
s.success = true
fmt.Println("Commit Metadata successful, Response :", response)
}
}

func (s *StatusBar) RepairCompleted(filesRepaired int) {
defer s.wg.Done()
allocUnderRepair = false
Expand Down Expand Up @@ -104,23 +91,6 @@ func PrintInfo(v ...interface{}) {
fmt.Fprintln(os.Stdin, v...)
}

func commitMetaTxn(path, crudOp, authTicket, lookupHash string, a *sdk.Allocation, fileMeta *sdk.ConsolidatedFileMeta, status *StatusBar) {
err := a.CommitMetaTransaction(path, crudOp, authTicket, lookupHash, fileMeta, status)
if err != nil {
PrintError("Commit failed.", err)
os.Exit(1)
}
}

func commitFolderTxn(operation, preValue, currValue string, a *sdk.Allocation) {
resp, err := a.CommitFolderChange(operation, preValue, currValue)
if err != nil {
PrintError("Commit failed.", err)
os.Exit(1)
}
fmt.Println("Commit Metadata successful, Response :", resp)
}

func init() {
log.SetOutput(os.Stdout)
log.SetFlags(0)
Expand Down
48 changes: 5 additions & 43 deletions cmd/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package cmd

import (
"fmt"
"os"
"sync"

"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -36,52 +34,16 @@ var copyCmd = &cobra.Command{
fmt.Println("Error fetching the allocation", err)
return
}
remotepath := cmd.Flag("remotepath").Value.String()
destpath := cmd.Flag("destpath").Value.String()
commit, _ := cmd.Flags().GetBool("commit")
remotePath := cmd.Flag("remotepath").Value.String()
destPath := cmd.Flag("destpath").Value.String()

statsMap, err := allocationObj.GetFileStats(remotepath)
if err != nil {
PrintError("Error in getting information about the object." + err.Error())
os.Exit(1)
}
isFile := false
for _, v := range statsMap {
if v != nil {
isFile = true
break
}
}

var fileMeta *sdk.ConsolidatedFileMeta
if isFile && commit {
fileMeta, err = allocationObj.GetFileMeta(remotepath)
if err != nil {
PrintError("Failed to fetch metadata for the given file", err.Error())
os.Exit(1)
}
}

err = allocationObj.CopyObject(remotepath, destpath)
err = allocationObj.CopyObject(remotePath, destPath)
if err != nil {
fmt.Println(err.Error())
return
}

fmt.Println(remotepath + " copied")
if commit {
fmt.Println("Commiting changes to blockchain ...")
if isFile {
wg := &sync.WaitGroup{}
statusBar := &StatusBar{wg: wg}
wg.Add(1)
commitMetaTxn(remotepath, "Copy", "", "", allocationObj, fileMeta, statusBar)
wg.Wait()
} else {
commitFolderTxn("Copy", remotepath, destpath, allocationObj)
}
}
return
fmt.Println(remotePath + " copied")
},
}

Expand All @@ -90,7 +52,7 @@ func init() {
copyCmd.PersistentFlags().String("allocation", "", "Allocation ID")
copyCmd.PersistentFlags().String("remotepath", "", "Remote path of object to copy")
copyCmd.PersistentFlags().String("destpath", "", "Destination path for the object. Existing directory the object should be copied to")
copyCmd.Flags().Bool("commit", false, "pass this option to commit the metadata transaction")

copyCmd.MarkFlagRequired("allocation")
copyCmd.MarkFlagRequired("remotepath")
copyCmd.MarkFlagRequired("destpath")
Expand Down
Loading