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

Use correct CIDs #41

Merged

Conversation

corrideat
Copy link
Member

@corrideat corrideat commented Jan 5, 2025

@corrideat corrideat requested a review from taoeffect January 5, 2025 17:49
@corrideat corrideat force-pushed the 1927-design-implement-contract-deletion-op_contract_delete-1 branch from 4023661 to d7abc7b Compare January 5, 2025 18:42
src/deploy.ts Outdated
@@ -13,11 +13,11 @@ export async function deploy (args: string[]) {
const json = JSON.parse(Deno.readTextFileSync(manifestPath))
const body = JSON.parse(json.body)
const dirname = path.dirname(manifestPath)
toUpload.push(path.join(dirname, body.contract.file))
toUpload.push('t|' + path.join(dirname, body.contract.file))
Copy link
Member

Choose a reason for hiding this comment

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

What is this t| and m| stuff? Can you add a comment explaining?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a prefix because we need to know what kind of CID should be used.

src/upload.ts Outdated
Comment on lines 17 to 36
for (const filepath_ of files) {
let type = multicodes.RAW
let filepath = filepath_
if (filepath_[1] === '|') {
switch (filepath_[0]) {
case 'r':
// raw file type
break
case 'm':
type = multicodes.SHELTER_CONTRACT_MANIFEST
break
case 't':
type = multicodes.SHELTER_CONTRACT_TEXT
break
default:
throw new Error('Unknown file type: ' + filepath_[0])
}
filepath = filepath_.slice(2)
}
const entry = await createEntryFromFile(filepath, type)
Copy link
Member

Choose a reason for hiding this comment

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

Is it not a concern that a user might use chel upload on a file that has | as the 2nd character?

Copy link
Member Author

@corrideat corrideat Jan 15, 2025

Choose a reason for hiding this comment

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

Files can't have | on Windows (one of the reasons I chose it; maybe the same goes for macOS, but I can't remember). However, for such files, they could be prefixed as needed. E.g., if the filename is ||, one could use r|||

Copy link
Member Author

Choose a reason for hiding this comment

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

On POSIX, only 0x00 (and maybe /) is an invalid character in file name, but using 0x00 for this purpose looked wrong, as it's difficult to type in a terminal.

Copy link
Member

Choose a reason for hiding this comment

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

OK, then do you make sure that everywhere upload is called the passed in files are prefixed?

And if they're all prefixed, what's the point of check on line 20? Instead, we should probably throw an exception if | isn't found.

Copy link
Member Author

Choose a reason for hiding this comment

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

The intent was to allow the command to be used from the command line without a prefix (in which case a raw id would be used)

Copy link
Member

Choose a reason for hiding this comment

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

Then we can invent some other flag or function for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

But a flag wouldn't work very well because the upload command works with multiple files.

Copy link
Member

Choose a reason for hiding this comment

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

We cannot have ambiguity here because such ambiguity would lead to unexpected behavior and bugs.

With a flag the user would be able to specify the type for all passed in files, and call the command again if they want to specify a different type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, but I don't really see the ambiguity here as | is pretty rare as a file name, and I expect that having a file called r|XX and another one called XX is even rarer.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, it's rare, but not so rare that it never happens. On macOS | is a valid filename character. If we can fix this now and forget about it, we don't need to ever worry about it in the future.

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

Yeah I think just eliminating all chance of any confusion over the filename prefixes and this PR is good to merge 👍

@corrideat corrideat force-pushed the 1927-design-implement-contract-deletion-op_contract_delete-1 branch from 69e7d92 to 405d425 Compare January 16, 2025 18:28
@corrideat corrideat requested a review from taoeffect January 16, 2025 18:30
Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

Nice!

@taoeffect taoeffect merged commit 5ca2aa0 into master Jan 16, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants