Skip to content

Commit

Permalink
Merge pull request #153 from ardriveapp/dev
Browse files Browse the repository at this point in the history
PE-676: Release ArDrive CLI v1.0.3
  • Loading branch information
fedellen authored Nov 10, 2021
2 parents 06f2720 + 7f7500b commit 4f537ed
Show file tree
Hide file tree
Showing 12 changed files with 564 additions and 171 deletions.
35 changes: 29 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,35 @@ Users can perform a bulk upload by using the upload-file command on a target fol
ardrive upload-file --local-file-path /path/to/folder --parent-folder-id "9af694f6-4cfc-4eee-88a8-1b02704760c0" -w /path/to/wallet.json
```

This method of upload can be used to upload a large number of files and folders within the folder tree. If existing entities are encountered in the destination folder tree that would cause naming conflicts, expect the following behaviors:
### Name Conflict Resolution on Upload

- Folder names that conflict with a FILE name at the destination will cause an error to be thrown
- Folder names that conflict with a FOLDER name at the destination will use the existing folder ID (i.e. skip) rather than creating a new folder
- File names that conflict with a FOLDER name at the destination will cause an error to be thrown
- File names that conflict with a FILE name at the destination will be uploaded as a REVISION
By default, the `upload-file` command will use the upsert behavior if existing entities are encountered in the destination folder tree that would cause naming conflicts.

Expect the behaviors from the following table for each resolution setting:

| Source Type | Conflict at Dest | `skip` | `replace` | `upsert` (default) |
| ----------- | ---------------- | ------ | --------- | ------------------ |
| File | None | Insert | Insert | Insert |
| File | Matching File | Skip | Update | Skip |
| File | Different File | Skip | Update | Update |
| File | Folder | Skip | Fail | Fail |
| Folder | None | Insert | Insert | Insert |
| Folder | File | Skip | Fail | Fail |
| Folder | Folder | Re-use | Re-use | Re-use |

The default upsert behavior will check the destination folder for a file with a conflicting name. If no conflicts are found, it will insert (upload) the file.

In the case that there is a FILE to FILE name conflict found, it will only update it if necessary. To determine if an update is necessary, upsert will compare the last modified dates of conflicting file and the file being uploaded. When they are matching, the upload will be skipped. Otherwise the file will be updated as a new revision.

To override the upsert behavior, use the `--replace` option to always make new revisions of a file or the `--skip` option to always skip the upload on name conflicts:

```shell
ardrive upload-file --replace --local-file-path /path/to/file.txt --parent-folder-id "9af694f6-4cfc-4eee-88a8-1b02704760c0" -w /path/to/wallet.json
```

```shell
ardrive upload-file --skip --local-file-path /path/to/file.txt --parent-folder-id "9af694f6-4cfc-4eee-88a8-1b02704760c0" -w /path/to/wallet.json
```

### Fetching the Metadata of a File Entity

Expand Down Expand Up @@ -880,7 +903,7 @@ ardrive <command> --help
[ardrive]: https://ardrive.io
[arweave]: https://ardrive.io/what-is-arweave/
[ardrive-github]: https://github.com/ardriveapp/
[arfs]: https://ardrive.atlassian.net/l/c/yDcGDbUm
[arfs]: https://ardrive.atlassian.net/l/c/m6P1vJDo
[ardrive-web-app]: https://app.ardrive.io
[ardrive-core]: https://github.com/ardriveapp/ardrive-core-js
[yarn-install]: https://yarnpkg.com/getting-started/install
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ardrive-cli",
"version": "1.0.2",
"version": "1.0.3",
"description": "The ArDrive Command Line Interface (CLI is a Node.js application for terminal-based ArDrive workflows. It also offers utility operations for securely interacting with Arweave wallets and inspecting various Arweave blockchain conditions.",
"main": "./lib/index.js",
"bin": {
Expand Down
21 changes: 20 additions & 1 deletion src/CLICommand/parameters_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import {
MaxDepthParameter,
SeedPhraseParameter,
WalletFileParameter,
PrivateParameter
PrivateParameter,
ReplaceParameter,
SkipParameter
} from '../parameter_declarations';
import { cliWalletDao } from '..';
import { DriveID, DriveKey } from '../types';
import passwordPrompt from 'prompts';
import { PrivateKeyData } from '../private_key_data';
import { ArweaveAddress } from '../arweave_address';
import { FileNameConflictResolution, replaceOnConflicts, skipOnConflicts, upsertOnConflicts } from '../ardrive';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type ParameterOptions = any;
Expand Down Expand Up @@ -204,6 +207,22 @@ export class ParametersHelper {
return maxDepthValue;
}

public getFileNameConflictResolution(): FileNameConflictResolution {
if (this.getParameterValue(ReplaceParameter)) {
return replaceOnConflicts;
}

if (this.getParameterValue(SkipParameter)) {
return skipOnConflicts;
}

// if (this.getParameterValue(AskParameter)) {
// return askOnConflicts;
// };

return upsertOnConflicts;
}

/**
* @param {ParameterName} parameterName
* @returns {string | undefined}
Expand Down
Loading

0 comments on commit 4f537ed

Please sign in to comment.