guacamole-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mjum...@apache.org
Subject [12/50] incubator-guacamole-server git commit: GUAC-236: Open output stream using file descriptor. Only write output file if it does not yet exist.
Date Sun, 20 Mar 2016 02:24:42 GMT
GUAC-236: Open output stream using file descriptor. Only write output file if it does not yet
exist.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/c50561ef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/c50561ef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/c50561ef

Branch: refs/heads/master
Commit: c50561ef10af1d40e7aa3bf1388ba79c2904567d
Parents: 73bf5ce
Author: Michael Jumper <mike.jumper@guac-dev.org>
Authored: Tue Mar 15 16:41:47 2016 -0700
Committer: Michael Jumper <mike.jumper@guac-dev.org>
Committed: Tue Mar 15 16:43:13 2016 -0700

----------------------------------------------------------------------
 src/guacenc/video.c | 19 +++++++++++++++++--
 src/guacenc/video.h |  7 ++++---
 2 files changed, 21 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/c50561ef/src/guacenc/video.c
----------------------------------------------------------------------
diff --git a/src/guacenc/video.c b/src/guacenc/video.c
index 99d990e..8c13844 100644
--- a/src/guacenc/video.c
+++ b/src/guacenc/video.c
@@ -34,10 +34,14 @@
 #include <guacamole/client.h>
 #include <guacamole/timestamp.h>
 
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <assert.h>
+#include <fcntl.h>
 #include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 guacenc_video* guacenc_video_alloc(const char* path, const char* codec_name,
         int width, int height, int bitrate) {
@@ -91,10 +95,18 @@ guacenc_video* guacenc_video_alloc(const char* path, const char* codec_name,
     }
 
     /* Open output file */
-    FILE* output = fopen(path, "wb");
-    if (output == NULL) {
+    int fd = open(path, O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR);
+    if (fd == -1) {
         guacenc_log(GUAC_LOG_ERROR, "Failed to open output file \"%s\": %s",
                 path, strerror(errno));
+        goto fail_output_fd;
+    }
+
+    /* Create stream for output file */
+    FILE* output = fdopen(fd, "wb");
+    if (output == NULL) {
+        guacenc_log(GUAC_LOG_ERROR, "Failed to allocate stream for output "
+                "file \"%s\": %s", path, strerror(errno));
         goto fail_output_file;
     }
 
@@ -123,6 +135,9 @@ fail_video:
     fclose(output);
 
 fail_output_file:
+    close(fd);
+
+fail_output_fd:
     av_freep(&frame->data[0]);
 
 fail_frame_data:

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/c50561ef/src/guacenc/video.h
----------------------------------------------------------------------
diff --git a/src/guacenc/video.h b/src/guacenc/video.h
index b9cbf13..61c7ff8 100644
--- a/src/guacenc/video.h
+++ b/src/guacenc/video.h
@@ -93,9 +93,10 @@ typedef struct guacenc_video {
 
 /**
  * Allocates a new guacenc_video which encodes video according to the given
- * specifications, saving the output in the given file. The output file will be
- * created if necessary and truncated if it already exists. Frames will be
- * scaled up or down as necessary to fit the given width and height.
+ * specifications, saving the output in the given file. If the output file
+ * already exists, encoding will be aborted, and the original file contents
+ * will be preserved. Frames will be scaled up or down as necessary to fit the
+ * given width and height.
  *
  * @param path
  *     The full path to the file in which encoded video should be written.


Mime
View raw message