-
Notifications
You must be signed in to change notification settings - Fork 45
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
Handle kill signal #123
base: main
Are you sure you want to change the base?
Handle kill signal #123
Changes from 2 commits
dc92169
709fd61
ccbb179
ad3e2a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import fs from 'fs' | ||
import os from 'os' | ||
|
||
import { CID } from 'multiformats' | ||
import { BaseBlockstore } from 'blockstore-core' | ||
|
@@ -10,9 +9,9 @@ export class FsBlockStore extends BaseBlockstore implements Blockstore { | |
_opened: boolean | ||
_opening?: Promise<void> | ||
|
||
constructor () { | ||
constructor (path: string) { | ||
super() | ||
this.path = `${os.tmpdir()}/${(parseInt(String(Math.random() * 1e9), 10)).toString() + Date.now()}` | ||
this.path = path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be a breaking change release for users bringing their own Blockstore on pack. I think we should do this change, but with retro compatibility. Let's default to the original value here if no path is provided? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is meant for the temporary directory which instead of being named with random numbers is named with something relevant to what's being packed (which helps users finding which one it is). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand and think your solution is better. But, also want to keep it compatible with older versions. What I mean here is we should fallback to the temporary directory being name randomly for people who don't provide a name. this.path = path || `${os.tmpdir()}/${(parseInt(String(Math.random() * 1e9), 10)).toString() + Date.now()}` This way, users that are relying on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I applied a change that should prevent custom blockstores from breaking, and still allow the clean up after a kill. |
||
this._opened = false | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import fs from 'fs' | ||
import os from 'os' | ||
import path from 'path' | ||
import moveFile from 'move-file' | ||
|
||
|
@@ -13,8 +12,10 @@ export interface PackToFsProperties extends PackProperties { | |
} | ||
|
||
export async function packToFs ({ input, output, blockstore: userBlockstore, hasher, maxChunkSize, maxChildrenPerNode, wrapWithDirectory, rawLeaves }: PackToFsProperties) { | ||
const blockstore = userBlockstore ? userBlockstore : new FsBlockStore() | ||
const location = output || `${os.tmpdir()}/${(parseInt(String(Math.random() * 1e9), 10)).toString() + Date.now()}` | ||
const realpath = path.basename(await fs.promises.realpath(input as string)) | ||
const inputBasename = realpath === "/" ? "file" : realpath | ||
const blockstore = userBlockstore ? userBlockstore : new FsBlockStore(`/tmp/${inputBasename}.tmp.${process.pid}`) | ||
const location = output || `${process.cwd()}/.${inputBasename}.car.tmp.${process.pid}` | ||
const writable = fs.createWriteStream(location) | ||
|
||
const { root } = await packToStream({ | ||
|
@@ -35,7 +36,7 @@ export async function packToFs ({ input, output, blockstore: userBlockstore, has | |
// Move to work dir | ||
if (!output) { | ||
const basename = typeof input === 'string' ? path.parse(path.basename(input)).name : root.toString() | ||
const filename = `${basename}.car` | ||
const filename = basename === "/" ? "file.car" : `${basename}.car` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. file.car is meant to be used when someone wants to pack up to his root (so someone wouldn't be packing its entire root at the same time multiple times). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the state of this discussion? |
||
await moveFile(location, `${process.cwd()}/${filename}`) | ||
|
||
return {root, filename} | ||
|
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.
Any reason to remove this bin emoji entry?
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.
As stated in the commit changing this,
The car is cute and fun but on an operational standpoint it is not usable.
In tty or on terminals not supporting this, it is hard to spot the process and to just enter the process name manually isn't possible this way.
I don't even see the car in htop even though my terminal supports the character which means that it is even incompatible with some applications that may be used on a server
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.
There is still the option to use
ipfs-car
command, so this change is out of scope of this PR. You can raise an issue to have it removed and explain the reasoning.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've reverted this change