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

Handle kill signal #123

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Breigner01
Copy link
Contributor

The temporary car file has been moved to the directory containing the folder or file being packed into the car.
This allows to not have to do multiple copies off of multiple drives (when the tmp folder may be on another drive).
The temporary file and folder have been renamed to make sense and allow people to see if the file is there and the name should make sense compared to the final one.

At the same time, now the kill signal is being handled and on kill, these are being deleted.

In order for the program to close somewhat cleanly, it now catches the
signal and deletes the temporary file and folder before quitting.
Also the temporary files have been renamed to have meaningful file names
This car is cute and all but on an operational standpoint it's not
practical and even on my own computer with fonts that handle these kinds
of characters, the car doesn't display in htop.
@vasco-santos vasco-santos self-requested a review May 16, 2022 14:10
package.json Outdated
@@ -8,7 +8,6 @@
"/dist"
],
"bin": {
"🚘": "./dist/cjs/cli/cli.js",
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Collaborator

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.

Copy link
Contributor Author

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

super()
this.path = `${os.tmpdir()}/${(parseInt(String(Math.random() * 1e9), 10)).toString() + Date.now()}`
this.path = path
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

@Breigner01 Breigner01 May 16, 2022

Choose a reason for hiding this comment

The 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).
Also, it allows reconstructing the folder name to delete it on SIGKILL or SIGTERM

Copy link
Collaborator

Choose a reason for hiding this comment

The 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 ipfs-car and providing a Blockstore from their side will not have unexpected changes without changing their code accordingly. Also, path is only relevant for FsBlockstore, so should really be optional and not required to keep interface the same for all blockstores

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@@ -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`
Copy link
Collaborator

Choose a reason for hiding this comment

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

file.car will be problematic for multiple packs in parallel as they will use same filename. Can we generate a random name like we used to do in blockstore ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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).
But otherwise it was meant to not use ..car when . is passed as the input directory but resolve the name of this directory instead.

Copy link
Contributor Author

@Breigner01 Breigner01 Jul 5, 2022

Choose a reason for hiding this comment

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

What's the state of this discussion?
I believe that it shouldn't be an issue but LMK.

@vasco-santos
Copy link
Collaborator

@Breigner01 can you also have a look into tests failing? TS compile is failing from what I can see

@Breigner01
Copy link
Contributor Author

@Breigner01 can you also have a look into tests failing? TS compile is failing from what I can see

Yeah I didn't see that, I might need to change the tests base on the changes I've made

This allows to not break custom blockstores and allow at the same
time clean kill signal handling.
@vasco-santos
Copy link
Collaborator

Thanks for the updates @Breigner01

Can you look into the tests too?

@Breigner01
Copy link
Contributor Author

Thanks for the updates @Breigner01

Can you look into the tests too?

I'll look into it on Monday, I can't see it clearly on mobile but have you reran the tests after the modifications I did recently?

@vasco-santos
Copy link
Collaborator

I'll look into it on Monday, I can't see it clearly on mobile but have you reran the tests after the modifications I did recently?

Thanks! Yeah, I ran CI for latest commit

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