Skip to content

Commit

Permalink
remove file first when overwriting
Browse files Browse the repository at this point in the history
  • Loading branch information
devernay committed Nov 18, 2021
1 parent 2f574d5 commit 39bbee7
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
8 changes: 8 additions & 0 deletions EXR/WriteEXR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <memory>

#include "ofxsMacros.h"
#include "ofxsFileOpen.h"

GCC_DIAG_OFF(deprecated)
#include <ImfChannelList.h>
Expand Down Expand Up @@ -207,6 +208,13 @@ WriteEXRPlugin::encode(const string& filename,
}

assert(pixelDataNComps);

// If the file exists (which means "overwrite" was checked), remove it first.
// See https://github.com/NatronGitHub/Natron/issues/666
if (OFX::exists_utf8( filename.c_str() )) {
OFX::remove_utf8( filename.c_str() );
}

try {
int compressionIndex;
_compression->getValue(compressionIndex);
Expand Down
8 changes: 7 additions & 1 deletion FFmpeg/WriteFFmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extern "C" {
}
#include "IOUtility.h"
#include "ofxsMacros.h"

#include "ofxsFileOpen.h"

#ifdef OFX_IO_USING_OCIO
#include "GenericOCIO.h"
Expand Down Expand Up @@ -3739,6 +3739,12 @@ WriteFFmpegPlugin::beginEncode(const string& filename,
return;
}

// If the file exists (which means "overwrite" was checked), remove it first.
// See https://github.com/NatronGitHub/Natron/issues/666
if (OFX::exists_utf8( filename.c_str() )) {
OFX::remove_utf8( filename.c_str() );
}

assert(!_formatContext);
if (!_formatContext) {
avformat_alloc_output_context2( &_formatContext, avOutputFormat, nullptr, filename.c_str() );
Expand Down
13 changes: 12 additions & 1 deletion OIIO/WriteOIIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,18 @@ WriteOIIOPlugin::beginEncodeParts(void* user_data,
}
} // switch


// If the file exists (which means "overwrite" was checked), remove it first.
// See https://github.com/NatronGitHub/Natron/issues/666
if (Filesystem::exists(filename)) {
string err;
bool ok = Filesystem::remove(filename, err);
if (!ok) {
setPersistentMessage(Message::eMessageError, "", err);
throwSuiteStatusException(kOfxStatFailed);
}
}
// Some formats only support opening all subimages at once.
// See https://openimageio.readthedocs.io/en/stable/imageoutput.html
if ( !data->output->open( filename, data->specs.size(), &data->specs.front() ) ) {
setPersistentMessage( Message::eMessageError, "", data->output->geterror() );
throwSuiteStatusException(kOfxStatFailed);
Expand Down
6 changes: 6 additions & 0 deletions PFM/WritePFM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ WritePFMPlugin::encode(const string& filename,
return;
}

// If the file exists (which means "overwrite" was checked), remove it first.
// See https://github.com/NatronGitHub/Natron/issues/666
if (OFX::exists_utf8( filename.c_str() )) {
OFX::remove_utf8( filename.c_str() );
}

std::FILE *const nfile = fopen_utf8(filename.c_str(), "wb");
if (!nfile) {
setPersistentMessage(Message::eMessageError, "", "Cannot open file \"" + filename + "\"");
Expand Down
6 changes: 6 additions & 0 deletions PNG/WritePNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,12 @@ WritePNGPlugin::encode(const string& filename,
return;
}

// If the file exists (which means "overwrite" was checked), remove it first.
// See https://github.com/NatronGitHub/Natron/issues/666
if (OFX::exists_utf8( filename.c_str() )) {
OFX::remove_utf8( filename.c_str() );
}

png_structp png = NULL;
png_infop info = NULL;
FILE* file = NULL;
Expand Down
2 changes: 1 addition & 1 deletion SupportExt

0 comments on commit 39bbee7

Please sign in to comment.