diff mbox series

[FFmpeg-devel,1/2] avformat/avio: fix ff_rename to respect used protocol

Message ID 20200108002340.24949-1-cus@passwd.hu
State Accepted
Headers show
Series [FFmpeg-devel,1/2] avformat/avio: fix ff_rename to respect used protocol
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Marton Balint Jan. 8, 2020, 12:23 a.m. UTC
Also simplify it, move it to avio.c and make it always log the error.

This fixes for example the image2 muxer when used with an URL which also
contains the protocol:

ffmpeg -f lavfi -i testsrc -vframes 10 -atomic_writing 1 file:out%d.png

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavformat/avio.c     |  9 +++++++++
 libavformat/internal.h | 20 ++++----------------
 2 files changed, 13 insertions(+), 16 deletions(-)

Comments

Michael Niedermayer Jan. 8, 2020, 10:21 p.m. UTC | #1
On Wed, Jan 08, 2020 at 01:23:39AM +0100, Marton Balint wrote:
> Also simplify it, move it to avio.c and make it always log the error.

I think at least moving and changing should be seperate so the diff shows
what is changed

thx

[...]
diff mbox series

Patch

diff --git a/libavformat/avio.c b/libavformat/avio.c
index 2dd2312296..65cfc0f4bb 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -26,6 +26,7 @@ 
 #include "libavutil/avassert.h"
 #include "os_support.h"
 #include "avformat.h"
+#include "internal.h"
 #if CONFIG_NETWORK
 #include "network.h"
 #endif
@@ -665,3 +666,11 @@  int ff_check_interrupt(AVIOInterruptCB *cb)
         return cb->callback(cb->opaque);
     return 0;
 }
+
+int ff_rename(const char *url_src, const char *url_dst, void *logctx)
+{
+    int ret = avpriv_io_move(url_src, url_dst);
+    if (ret < 0)
+        av_log(logctx, AV_LOG_ERROR, "failed to rename file %s to %s: %s\n", url_src, url_dst, av_err2str(ret));
+    return ret;
+}
diff --git a/libavformat/internal.h b/libavformat/internal.h
index ec9a29907a..332477a532 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -580,25 +580,13 @@  int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *a
 int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src);
 
 /**
- * Wrap errno on rename() error.
+ * Wrap avpriv_io_move and log if error happens.
  *
- * @param oldpath source path
- * @param newpath destination path
+ * @param url_src source path
+ * @param url_dst destination path
  * @return        0 or AVERROR on failure
  */
-static inline int ff_rename(const char *oldpath, const char *newpath, void *logctx)
-{
-    int ret = 0;
-    if (rename(oldpath, newpath) == -1) {
-        ret = AVERROR(errno);
-        if (logctx) {
-            char err[AV_ERROR_MAX_STRING_SIZE] = {0};
-            av_make_error_string(err, AV_ERROR_MAX_STRING_SIZE, ret);
-            av_log(logctx, AV_LOG_ERROR, "failed to rename file %s to %s: %s\n", oldpath, newpath, err);
-        }
-    }
-    return ret;
-}
+int ff_rename(const char *url_src, const char *url_dst, void *logctx);
 
 /**
  * Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end