#37 Can't overwrite existing file without creating .bak file

v1.0 (example)
closed-later
Cosmin Truta
None
5
2013-12-28
2013-03-07
Sindre Sorhus
No

I need to be able to overwrite existing files without creating a .bak file. I assumed that was the intention of `-force`, but that option doesn't let me overwrite. `-clobber` does, but creates a .bak file. And they apparently don't work together.

Can you make it possible to overwrite without creating a .bak file?

OptiPNG 0.7.4

Results:

no flag
The output file exists. Rerun OptiPNG with -backup enabled
Error: Can't overwrite the output file

-force
The output file exists. Rerun OptiPNG with -backup enabled
Error: Can't overwrite the output file

-clobber
Creates .bak files

-clobber -force
Creates .bak files

Discussion

  • Ian
    Ian
    2013-10-28

    I'm only on v0.6.4, but this isn't what I see. I'm also running on Linux which may account for some differences if you're on Windows. I don't have a -clobber option in my documentation and files are overwritten by default.

    -force is an option to always output a new file, even if it is bigger than before, nothing to do with overwriting or backups.
    -clobber, as documented (but not how it works for me) enables the existing file to be overwritten, although quite why this is an option is beyond me since optipng tries to overwrite the existing file by default. The development v1.0 deprecates this option and overwrites by default, with a -no-clobber option if you're not serious about it.
    The option to create a backup file is -backup or -keep, and the default is not to.

    So, assuming you are running a version (or platform) that doesn't clobber by default, specify the -clobber option and make sure you have permissions to the file.

     
  • Ian
    Ian
    2013-10-28

    After installing v0.7.4, still on Linux, files are still overwritten automatically, no need for the -clobber option which the manpage describes as having no effect and being deprecation.

     
  • Cosmin Truta
    Cosmin Truta
    2013-11-04

    I think the options -backup -clobber (both enabled) should do what you need.

    The option -clobber is messy, because the default behavior is messy. Specifically, the original PNG files are clobbered, but the imported files (GIF, BMP, etc.) are not. Moreover, the backup files, if they exist, are not clobbered. The option -clobber has the effect of clobbering everything.

    This will be fixed, in a backwards-incompatible way, in the future version. See OptiPNG-Hg. The new default behavior will be to clobber everything uniformly (i.e. like most other standard file manipulation tools), and then the option -no-clobber will have the effect not to clobber anything, also uniformly.

     
  • Cosmin Truta
    Cosmin Truta
    2013-11-04

    • status: open --> pending
    • Group: --> v1.0 (example)
     
  • Cosmin Truta
    Cosmin Truta
    2013-12-28

    • status: pending --> closed-later
    • assigned_to: Cosmin Truta
     
  • Cosmin Truta
    Cosmin Truta
    2013-12-28

    I think the options -backup -clobber (both enabled) should do what you need.

    When I said that, I misread your question, because (now I re-read it) you want the backup not to be created...

    The rest of my previous comment still applies. I can't do it in 0.7.x without breaking the existing behaviour, but what you requested is the default behaviour in OptiPNG-Hg.

    I am therefore marking this bug as Closed-Later.