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

Improve detection of input/output file name matching #2873

Closed
fulldecent opened this issue Sep 1, 2021 · 5 comments · Fixed by #2878
Closed

Improve detection of input/output file name matching #2873

fulldecent opened this issue Sep 1, 2021 · 5 comments · Fixed by #2878

Comments

@fulldecent
Copy link

Reading from and writing to the same file should be supported

@lovell
Copy link
Owner

lovell commented Sep 1, 2021

Hi, sorry, this is due to a performance benefit of libvips, which allows it to start writing to the output file whilst still reading the input file.

@lovell lovell added question and removed triage labels Sep 1, 2021
@fulldecent
Copy link
Author

That's cool.

Then could it please fail gracefully rather than clobbering the file?

@lovell
Copy link
Owner

lovell commented Sep 3, 2021

There is some simple logic to check for this:

sharp/lib/output.js

Lines 57 to 58 in e044788

} else if (this.options.input.file === fileOut) {
err = new Error('Cannot use same file for input and output');

Perhaps this should use something like path.resolve to handle relative paths? Happy to accept a PR for this, if you're able.

@lovell lovell changed the title mogrify Improve detection of input/output file name matching Sep 3, 2021
@lovell lovell reopened this Sep 6, 2021
@lovell lovell added this to the v0.29.1 milestone Sep 6, 2021
@fulldecent
Copy link
Author

This is great, thank you!

@lovell
Copy link
Owner

lovell commented Sep 7, 2021

v0.29.1 now available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants