Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

New CLI linux style command list #416

Merged
merged 71 commits into from
Feb 14, 2018
Merged

Conversation

aligeti
Copy link
Contributor

@aligeti aligeti commented Jan 31, 2018

Adding new commands to CLI supporting linux style

…name to be entered as part of the existing command. The command "storj list-buckets [bucket-name]" is used to list the bucket ID of corresponding bucket name, if found in the buckets list.

Example: If no bucket name specified, then the command lists all available buckets
./storj list-buckets
ID: 6cb2014a988adca6ed712577 	Decrypted: true 	Created: 2017-12-15T17:23:25.832Z 	Name: testbucket
ID: 725131c74690150e7b0cc747 	Decrypted: true 	Created: 2017-12-18T16:41:41.583Z 	Name: testbucket2
ID: 965efd4b5d65fd82643f5727 	Decrypted: true 	Created: 2017-12-18T18:14:05.098Z 	Name: testbucket3
ID: b20824d412f7a8845379769e 	Decrypted: true 	Created: 2017-12-18T18:15:05.270Z 	Name: testbucket4

Example: If bucket name is specified, then the command lists details specific to the entered bucket name
./storj list-buckets testbucket
ID: 6cb2014a988adca6ed712577 	Decrypted: true 	Created: 2017-12-15T17:23:25.832Z 	Name: testbucket

Example: If bucket name is specified, but doesnt exists, then the command return error
./storj list-buckets testbucketXYZ
Invalid bucket name.
Test Case storj-archived#1: No bucket name given
kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj -d list-files
Missing first argument: <bucket-id>

Test Case storj-archived#2: Complete command with valid bucket name with 2 files in it
kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj -d list-files testbucket
ID: 6cb2014a988adca6ed712577 	Decrypted: true 	Created: 2017-12-15T17:23:25.832Z 	Name: testbucket
ID: 27607c99600540cc4c57953c 	Size: 9 bytes 	Decrypted: true 	Type: application/octet-stream 	Created: 2017-12-15T17:27:25.461Z 	Name: testfile.txt
ID: ee2fcc89dfe71c932cf44fcc 	Size: 10 bytes 	Decrypted: true 	Type: application/octet-stream 	Created: 2017-12-15T17:29:38.994Z 	Name: testfile2.txt

Test Case storj-archived#3: Complete command with valid bucket name but no files in it
kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj -d list-files testbucket2
ID: 725131c74690150e7b0cc747 	Decrypted: true 	Created: 2017-12-18T16:41:41.583Z 	Name: testbucket2
No files for bucket.

Test Case storj-archived#4: Compete command with invalid bucket name
kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj -d list-files testbucket2233432
Invalid bucket name.
Checking in supports "storj list-files [bucket_name]"

Test Case storj-archived#1: No bucket name given
kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj -d list-files
Missing first argument: <bucket-id>

Test Case storj-archived#2: Complete command with valid bucket name with 2 files in it
kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj -d list-files testbucket
ID: 6cb2014a988adca6ed712577 	Decrypted: true 	Created: 2017-12-15T17:23:25.832Z 	Name: testbucket
ID: 27607c99600540cc4c57953c 	Size: 9 bytes 	Decrypted: true 	Type: application/octet-stream 	Created: 2017-12-15T17:27:25.461Z 	Name: testfile.txt
ID: ee2fcc89dfe71c932cf44fcc 	Size: 10 bytes 	Decrypted: true 	Type: application/octet-stream 	Created: 2017-12-15T17:29:38.994Z 	Name: testfile2.txt

Test Case storj-archived#3: Complete command with valid bucket name but no files in it
kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj -d list-files testbucket2
ID: 725131c74690150e7b0cc747 	Decrypted: true 	Created: 2017-12-18T16:41:41.583Z 	Name: testbucket2
No files for bucket.

Test Case storj-archived#4: Compete command with invalid bucket name
kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj -d list-files testbucket2233432
Invalid bucket name.

on branches master
branches master
==========================================================================================================

Testcase storj-archived#1: No aruguments entered

kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj upload-file
Missing arguments: <bucket-name> <path>
========================================================================================================

LIST ALLTHE VALID BUCKETS NAMES

kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj list-buckets
ID: 6cb2014a988adca6ed712577 	Decrypted: true 	Created: 2017-12-15T17:23:25.832Z 	Name: testbucket
ID: 725131c74690150e7b0cc747 	Decrypted: true 	Created: 2017-12-18T16:41:41.583Z 	Name: testbucket2
ID: 965efd4b5d65fd82643f5727 	Decrypted: true 	Created: 2017-12-18T18:14:05.098Z 	Name: testbucket3
ID: b20824d412f7a8845379769e 	Decrypted: true 	Created: 2017-12-18T18:15:05.270Z 	Name: testbucket4

=========================================================================================================
PICK A BUCKET AND LIST ALL THE FILES IN THAT BUCKET

kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj list-files testbucket2
ID: 725131c74690150e7b0cc747 	Decrypted: true 	Created: 2017-12-18T16:41:41.583Z 	Name: testbucket2
ID: 4022eed501eb8d008ce61b84 	Size: 22 bytes 	Decrypted: true 	Type: application/octet-stream 	Created: 2017-12-21T23:39:17.352Z 	Name: testfileA.txt

==========================================================================================================

TEST CASE#2: Execute the complete upload-file command

kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj upload-file testbucket2 testjson.json
ID: 725131c74690150e7b0cc747 	Decrypted: true 	Created: 2017-12-18T16:41:41.583Z 	Name: testbucket2
[======================================================================] 100.00%
Upload Success! File ID: 037431e2b0489b41db7a363d

==========================================================================================================
LIST THE FILES IN THE ABOVE UPLOADED BUCKET TO VERIFY THAT THE NEW FILES IS LISTED AS WELL

kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj list-files testbucket2
ID: 725131c74690150e7b0cc747 	Decrypted: true 	Created: 2017-12-18T16:41:41.583Z 	Name: testbucket2
ID: 4022eed501eb8d008ce61b84 	Size: 22 bytes 	Decrypted: true 	Type: application/octet-stream 	Created: 2017-12-21T23:39:17.352Z 	Name: testfileA.txt
ID: 037431e2b0489b41db7a363d 	Size: 1448 bytes 	Decrypted: true 	Type: application/octet-stream 	Created: 2017-12-22T13:56:16.628Z 	Name: testjson.json

==========================================================================================================

TEST CASE#3: VALID BUCKET NAME AND INVALID FILE-NAME

kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj upload-file testbucket2 testjson.jsondsf
ID: 725131c74690150e7b0cc747 	Decrypted: true 	Created: 2017-12-18T16:41:41.583Z 	Name: testbucket2
Invalid file path: testjson.jsondsf

==========================================================================================================

TEST CASE#4: INVALID BUCKET NAME AND INVALID FILE-NAME

kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj upload-file testbucket2sfs testjson.jsondsf
Invalid bucket name.

==========================================================================================================

TEST CASE#4: INVALID BUCKET NAME AND VALID FILE-NAME

kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj upload-file testbucket3sfs testjson.json
Invalid bucket name.

==========================================================================================================

TEST CASE#5: VALID BUCKET NAME AND VALID FILE-NAME

kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj upload-file testbucket3 testjson.json
ID: 965efd4b5d65fd82643f5727 	Decrypted: true 	Created: 2017-12-18T18:14:05.098Z 	Name: testbucket3
[======================================================================] 100.00%
Upload Success! File ID: f10d046334eea2e7a6ba9723

==========================================================================================================

TEST CASE#6: TRY AGAIN TO UPLOAD THE SAME FILE WITH VALID BUCKET NAME AND VALID FILE-NAME

kishore@kishore-Inspiron-13-7353:~/libstorj/src$ ./storj upload-file testbucket3 testjson.json
ID: 965efd4b5d65fd82643f5727 	Decrypted: true 	Created: 2017-12-18T18:14:05.098Z 	Name: testbucket3
Preparing File...
Upload failure: File already exists
==========================================================================================================
…>/<filename>

--> ./storj cp /home/kishore/libstorj/src/teset1 storj://testbucket/*              --> Invalid target filename
--> ./storj cp /home/kishore/libstorj/src/teset1 storj://testbucket/.              --> uploads correctly
--> ./storj cp /home/kishore/libstorj/src/teset1 storj://testbucket/teset2         --> Invalid target filename
--> ./storj cp /home/kishore/libstorj/src/teset1 storj://testbucket/teset1         --> uploads correctly
Modified the file_exists() to verify the local filename entered is either a directory or a file. Also if it is a directory will print out all the files recursively( from sub directories)
…vely. Commented the printf statements. Uncommenting them, you can see on the stdio
Added the functionality to test
./storj cp /home/kishore/libstorj/src/teset1 storj://testbucket/teset1
./storj cp /home/kishore/libstorj/src/teset1 storj://testbucket/.
./storj cp /home/kishore/libstorj/src/teset1 storj://testbucket/

./storj cp -r[R] /home/kishore/libstorj/src/teset1
storj://testbucket/teset1
./storj cp -r[R] /home/kishore/libstorj/src/teset1 storj://testbucket/.
./storj cp -r[R] /home/kishore/libstorj/src/teset1 storj://testbucket/

Working on uploading the file recursively.
Working on recursive uploads

Current implementation

./storj cp /home/kishore/libstorj/src/teset1 storj://testbucket/teset1
./storj cp /home/kishore/libstorj/src/teset1 storj://testbucket/.
./storj cp /home/kishore/libstorj/src/teset1 storj://testbucket/

./storj cp -r[R] /home/kishore/libstorj/src/teset1
storj://testbucket/teset1
./storj cp -r[R] /home/kishore/libstorj/src/teset1 storj://testbucket/.
./storj cp -r[R] /home/kishore/libstorj/src/teset1 storj://testbucket/
./storj cp -r /home/kishore/libstorj/src/ storj://testbucket/
…le command using storj cp [-rR]storj://<bucket-name>/<file-name> <local_download_path>
Supported CLI commands

./storj get-bucket-id <bucket-name>

Example:
./storj get-bucket-id testbucket
ID: 6cb2014a988adca6ed712577 	Decrypted: true 	Created: 2018-01-04T16:55:29.832Z 	Name: testbucket

./storj upload-file <bucket-name> <path-to-local-file-name>

Example:
./storj upload-file testbucket3 uploader.lo
ID: 965efd4b5d65fd82643f5727 	Decrypted: true 	Created: 2017-12-18T18:14:05.098Z 	Name: testbucket3
[======================================================================] 100.00%
Upload Success! File ID: b8c4543226e9c65f61aa0141

./storj download-file <bucket-name> <file-name> <path-to-local-file-name>

Example: Local file name not given
./storj download-file testbucket3 uploader.o /tmp/.
ID: 965efd4b5d65fd82643f5727 	Decrypted: true 	Created: 2017-12-18T18:14:05.098Z 	Name: testbucket3
stat: No such file or directory
Warning: File already exists at path [/tmp/.].
Would you like to overwrite [/tmp/.]: [y/n] y
Unable to open /tmp/.: Is a directory

Example: Local file name given
./storj download-file testbucket3 uploader.o /tmp/uploader.ks
ID: 965efd4b5d65fd82643f5727 	Decrypted: true 	Created: 2017-12-18T18:14:05.098Z 	Name: testbucket3
[======================================================================] 100.00%
Download Success!

Example: Downloading with a filename that already exists locally
./storj download-file testbucket3 uploader.o /tmp/uploader.ks
ID: 965efd4b5d65fd82643f5727 	Decrypted: true 	Created: 2017-12-18T18:14:05.098Z 	Name: testbucket3
Warning: File already exists at path [/tmp/uploader.ks].
Would you like to overwrite [/tmp/uploader.ks]: [y/n] y
[======================================================================] 100.00%
Download Success!

./storj list-files <testbucket-name>

Example: List files in a bucket using bucket name
./storj list-files testbucket3
ID: 965efd4b5d65fd82643f5727 	Decrypted: true 	Created: 2017-12-18T18:14:05.098Z 	Name: testbucket3
ID: f10d046334eea2e7a6ba9723 	Size: 1448 bytes 	Decrypted: true 	Type: application/octet-stream 	Created: 2017-12-22T13:57:52.415Z 	Name: testjson.json
ID: 0f58c36885553516ccb63141 	Size: 9200 bytes 	Decrypted: true 	Type: application/octet-stream 	Created: 2018-01-09T16:53:18.496Z 	Name: teset1
ID: 190dc667ba33a72b00e3dbb7 	Size: 16528 bytes 	Decrypted: true 	Type: application/octet-stream 	Created: 2018-01-09T17:30:28.090Z 	Name: rs.o
ID: f25ae0dde4fb7b3559e8f089 	Size: 94808 bytes 	Decrypted: true 	Type: application/octet-stream 	Created: 2018-01-09T17:31:03.138Z 	Name: uploader.o
ID: b8c4543226e9c65f61aa0141 	Size: 279 bytes 	Decrypted: true 	Type: application/octet-stream 	Created: 2018-01-09T17:32:02.076Z 	Name: uploader.lo

./storj cp <path-to-local-filename> storj://<bucket-name>/<target-file-name>
./storj cp <path-to-local-filename> storj://<bucket-name>/.
./storj cp <path-to-local-filename> storj://<bucket-name>/<blank>

Example: uploading a file using ‘cp’ command. The target file name should be same as the upload file name, or ‘.’ or blank(no target file name)

Example: Using uploaded file name same as uploading same file
./storj cp /tmp/uploader.ksa storj://testbucket/uploader.ksa
ID: 6cb2014a988adca6ed712577 	Decrypted: true 	Created: 2018-01-04T16:55:29.832Z 	Name: testbucket
[======================================================================] 100.00%
Upload Success! File ID: 3092473ebc48a2d469a4a59d

Example: Using uploaded file name same as uploading same file, trying to upload a file already uploaded
./storj cp uploader.o storj://testbucket3/uploader.o
ID: 965efd4b5d65fd82643f5727 	Decrypted: true 	Created: 2017-12-18T18:14:05.098Z 	Name: testbucket3
Preparing File...
Upload failure: File already exists

Example: Uploading a file to a different bucket
./storj cp uploader.o storj://testbucket2/uploader.o
ID: 725131c74690150e7b0cc747 	Decrypted: true 	Created: 2017-12-18T16:41:41.583Z 	Name: testbucket2
[======================================================================] 100.00%
Upload Success! File ID: 6b82f6030fc688336190d768

Example: Using uploaded file name is entered as ‘.’

 ./storj cp http.o  storj://testbucket3/.
ID: 965efd4b5d65fd82643f5727 	Decrypted: true 	Created: 2017-12-18T18:14:05.098Z 	Name: testbucket3
[======================================================================] 100.00%
Upload Success! File ID: 65ac6ea61a175d06bcfa7567

Example: Missing uploaded file name (no file name entered or is blank)

./storj cp rs.lo storj://testbucket3/
[2212] target file name = rs.lo
ID: 965efd4b5d65fd82643f5727 	Decrypted: true 	Created: 2017-12-18T18:14:05.098Z 	Name: testbucket3
[======================================================================] 100.00%
Upload Success! File ID: fcd43a40f4543366d09ddb5c
./storj cp storj://<bucket-name>/<target-file-name> <path-to-local-filename>

Example: Downloaded file (teset1) same as the downloading file(teset1)
./storj cp storj://testbucket/teset1 /tmp/teset1
ID: 6cb2014a988adca6ed712577 	Decrypted: true 	Created: 2018-01-04T16:55:29.832Z 	Name: testbucket
[======================================================================] 100.00%
Download Success!

Example: Downloaded file(teset2) different from downloading file(teset1)
./storj cp storj://testbucket/teset1 /tmp/teset2
ID: 6cb2014a988adca6ed712577 	Decrypted: true 	Created: 2018-01-04T16:55:29.832Z 	Name: testbucket
[======================================================================] 100.00%
Download Success!

Example: Downloading same as above. The command prompts to overwrite?
./storj cp storj://testbucket/teset1 /tmp/teset2
ID: 6cb2014a988adca6ed712577 	Decrypted: true 	Created: 2018-01-04T16:55:29.832Z 	Name: testbucket
Warning: File already exists at path [/tmp/teset2].
Would you like to overwrite [/tmp/teset2]: [y/n] y
[======================================================================] 100.00%
Download Success!

Example: Downloaded file name not given
./storj cp storj://testbucket/teset1 /tmp/
ID: 6cb2014a988adca6ed712577 	Decrypted: true 	Created: 2018-01-04T16:55:29.832Z 	Name: testbucket
Warning: File already exists at path [/tmp/].
Would you like to overwrite [/tmp/]: [y/n] y
Unable to open /tmp/: Is a directory

Example: Downloaded file name is ‘.’
./storj cp storj://testbucket/teset1 /tmp/.
ID: 6cb2014a988adca6ed712577 	Decrypted: true 	Created: 2018-01-04T16:55:29.832Z 	Name: testbucket
Warning: File already exists at path [/tmp/.].
Would you like to overwrite [/tmp/.]: [y/n] y
Unable to open /tmp/.: Is a directory

Example: Downloaded file name is ‘*’-- DONT USE THIS COMMAND. It will overwrite the first file in the directory and renames it to the downloading file name.
./storj cp storj://testbucket/http.o /tmp/*
ID: 6cb2014a988adca6ed712577 	Decrypted: true 	Created: 2018-01-04T16:55:29.832Z 	Name: testbucket
Warning: File already exists at path [/tmp/Aac.o].
Would you like to overwrite [/tmp/Aac.o]: [y/n] y
[======================================================================] 100.00%
Download Success!
This reverts commit f0cfe08ba703d5f5563d20e34801e3c34cdfe120.
src/cli.c Outdated
int ret = strpos(cmd_str, sub_str);
if( ret == -1)
{
printf("Invalid Command Entry (%d), \ntry ... stroj://<bucket_name>/<file_name>\n", ret);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo should be storj not stroj

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the typo

@aleitner
Copy link
Contributor

aleitner commented Feb 7, 2018

3 things need to be fixed before merging

  • Remove-file, and list-mirrors prints all the files in a bucket
  • Can't do anything by file id anymore
  • Fix typo where stroj was typed instead of storj

@braydonf
Copy link
Contributor

braydonf commented Feb 7, 2018

I would leave the existing commands, such as list-files,
list-buckets, upload-file and download-file as-is and add a new
section for the unix fs style of commands with different argument
formats, example:

usage: storj [<options>] <command> [<args>]

These are common Storj commands for various situations:

setting up users profiles
  register                  setup a new storj bridge user
  import-keys               import existing user
  export-keys               export bridge user, password and encryption keys

unix style commands
  ls (lists the available buckets)
  ls <bucket-name> (lists the files in a bucket)
  rm <bucket-name> (remove bucket)
  rm <bucket-name> <file-name> (to remove file in a bucket)
  cp [-rR] <path-to-local-file-name> storj://<bucketname>/file-name
  mkbkt <bucket-name> (make a bucket)

working with buckets and files
  list-buckets
  list-files <bucket-id>
  remove-file <bucket-id> <file-id>
  add-bucket <name> 
  remove-bucket <bucket-id>
  list-mirrors <bucket-id> <file-id>

downloading and uploading files
  upload-file <bucket-id> <path>
  download-file <bucket-id> <file-id> <path

bridge api information
  get-info

...

src/storj.c Outdated
storj_api->excp_cmd_resp = "get-bucket-id-resp";

/* when callback returns, we store the bucket id of bucket name else null */
return storj_bridge_get_buckets(storj_api->env, storj_api, get_bucket_id_callback);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be storj_bridge_get_bucket_id, which was recently added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just happened to be a coincidence, I am open for renaming the function. For the time being I will leave there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the function name to cli-get-bucket_id()

src/cli.c Outdated
{
struct stat sb;

if (stat(file_path, &sb) == -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the style for brackets is on the same line for everything except functions, e.g.:

if (stat(file_path, &sb) == -1) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the braces indentation as per the suggestion

Copy link
Contributor

@braydonf braydonf Feb 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still looks like these are unchanged (bracket styles).

src/Makefile.am Outdated
@@ -1,5 +1,5 @@
lib_LTLIBRARIES = libstorj.la
libstorj_la_SOURCES = storj.c utils.c utils.h http.c http.h uploader.c uploader.h downloader.c downloader.h bip39.c bip39.h bip39_english.h crypto.c crypto.h rs.c rs.h
libstorj_la_SOURCES = storj.c utils.c utils.h http.c http.h uploader.c uploader.h downloader.c downloader.h bip39.c bip39.h bip39_english.h crypto.c crypto.h rs.c rs.h storjapi_callback.c storjapi_callback.h
Copy link
Contributor

@braydonf braydonf Feb 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of storjapi_callback.c and storjapi_callback.h it could be more clear as cli_callback.c and cli_callback.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the file names from Storjapi_callback.h/c to cli_callback.h/c

@braydonf
Copy link
Contributor

braydonf commented Feb 7, 2018

Adding storj_list_buckets (and the others) to the exposed API in storj.h with already existing
storj_bridge_list_buckets will be confusing. We can encapsulate those methods to be specific to the CLI rather than exposed in storj.h?

src/cli.c Outdated

storj_api->env = env;

#ifdef debug_enable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a logger that can be used that will enable/disable debug based on settings (e.g. using --debug), example usage:

state->log->debug(env->log_options, NULL /*handle pointer*/, "Some debug message: %i", some_integer);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently printf's that I left in the code is used to printout error conditions. Will look into adding log->debug usage


#include "storj.h"

#define CLI_NO_SUCH_FILE_OR_DIR 0x00
Copy link
Contributor

@braydonf braydonf Feb 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are defined twice? Once here and another in cli.c.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the duplication.

@bryanchriswhite
Copy link
Contributor

@braydonf it seems like it would be beneficial to expose the functions that take bucket/file names as well as those that take IDs; e.g. binding libraries would have to re-implement the name decryption/lookup if the new methods aren't exposed.

I could imagine the solution either being to rename things to be less ambiguous or to move the new functionality to a helper module or something (i.e. not in cli.c) that can also be referenced by libstorj api consumers.

…torj api call from storj.c instead of reading bucket list and doing a string compare; 3. moved the cli_api_t structure to cli_callback.h and renamed the structure to cli_api_t
@braydonf
Copy link
Contributor

@bryanchriswhite Yes, those methods have been exposed already as storj_bridge_get_bucket_id and storj_bridge_get_file_id from #414 and included in v2.0.0-beta2

src/uploader.c Outdated
@@ -370,7 +370,7 @@ static void after_create_bucket_entry(uv_work_t *work, int status)
state->info->id = NULL;
state->info->bucket_id = state->bucket_id;
state->info->decrypted = true;
state->info->index = strdup(state->index);
state->info->index = state->index;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may have been a regression, state->info->index = strdup(state->index); is how this should be (and should go along with leaving the free to file->index in storj_free_uploaded_file_info.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made changes per the comment


#include "storj.h"

#if defined(_WIN32) && defined(STORJDLL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This DLL export stuff isn't needed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the CLI_API references

}


CLI_API int cli_list_buckets(cli_api_t *cli_api)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These CLI_API are not needed here, only relevant for DLL exporting.

src/cli.c Outdated
{
struct stat sb;

if (stat(file_path, &sb) == -1)
Copy link
Contributor

@braydonf braydonf Feb 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still looks like these are unchanged (bracket styles).

src/cli.c Outdated
" upload-file <bucket-id> <path>\n" \
" download-file <bucket-id> <file-id> <path>\n" \
" cp [-rR] <path-to-local-file-name> " \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grouping the unix style commands in the help text I think would be useful (example from comment at #416 (comment))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the parenthesis and grouped the linux style commands

…grouped the linux style commands, updated the uploader file( not sure why it didnt merge when I did the fetch from upstream), but anyhow merged the changes explicitly
Copy link
Contributor

@braydonf braydonf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like most issue have been addressed! Found a couple of smaller formatting issues (easy fixes).

printf("command = %s; command_index = %d\n", command, command_index);
printf("local_file_path (req arg_ = %s\n", local_file_path);
for (int i = 0x00; i < argc; i++)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another { on newline, instead of same line

char sub_str[] = "storj://";
ret = strpos(dst_path, sub_str);

if( ret == 0x00) { /* Handle upload command*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small spacing issue: should be if ( instead of if(


cmd_type = UPLOAD_CMD;
}
else if (ret == -1) { /* Handle download command*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: newline, instead of same line

/* set the file to be downloaded */
cli_api->file_name = token[2];

if ((check_file_path(local_file_path) == CLI_VALID_DIR) || (strcmp(dst_file_name, ".") == 0x00)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potential max line length issues here?

printf("[%s][%d] Valid dst filename missing !!!!!\n", __FUNCTION__, __LINE__);
goto end_program;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: } else { instead of the newline


cli_list_mirrors(cli_api);
} else
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: newline

@@ -1485,5 +1582,9 @@ int main(int argc, char **argv)
if (mnemonic) {
free(mnemonic);
}
if(cli_api){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spacing, instead if (cli_api) {

@@ -0,0 +1,1168 @@
#include "cli_callback.h"

//#define debug_enable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extraneous variable

char * start;
cli_api_t *cli_api = handle;

if((dp = opendir(dir)) == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spacing

}

switch (sb.st_mode & S_IFMT)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: newline

@braydonf
Copy link
Contributor

@aligeti Also, please don't forget to take the WIP off the title when you're ready to merge.

@braydonf
Copy link
Contributor

Went ahead and made some of the above changes already, and included in: #422

@aligeti
Copy link
Contributor Author

aligeti commented Feb 14, 2018 via email

@braydonf braydonf changed the title WIP: New CLI linux style command list New CLI linux style command list Feb 14, 2018
@braydonf braydonf merged commit 42336cb into storj-archived:master Feb 14, 2018
@braydonf
Copy link
Contributor

Cool, it's merged so we can get more testing.

FYI you can include Closes #354 in the description on the PR and it will automatically close the issue once merged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants