-
Notifications
You must be signed in to change notification settings - Fork 1
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
Use correct CIDs #41
Conversation
4023661
to
d7abc7b
Compare
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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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|||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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 👍
69e7d92
to
405d425
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
EDIT (by @taoeffect): see also: multiformats/multicodec#369