Skip to content

Commit

Permalink
Create missing directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Minter committed Jan 24, 2021
1 parent eda3b87 commit 2b3eb35
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.0)
project(ReplaySorcery VERSION 0.5.0)
include(CheckCCompilerFlag)
include(CheckIncludeFile)
include(CheckSymbolExists)
include(ExternalProject)
find_package(PkgConfig REQUIRED)

Expand Down Expand Up @@ -143,8 +143,9 @@ if (LIBDRM_FOUND)
endif()

# Build configuration
check_include_file(unistd.h RS_BUILD_UNISTD_FOUND)
check_include_file(fcntl.h RS_BUILD_FCNTL_FOUND)
check_symbol_exists(read unistd.h RS_BUILD_READ_FOUND)
check_symbol_exists(fcntl fcntl.h RS_BUILD_FCNTL_FOUND)
check_symbol_exists(mkdir sys/stat.h RS_BUILD_MKDIR_FOUND)
configure_file(src/rsbuild.h.in rsbuild.h)
target_include_directories(${binary} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

Expand Down
12 changes: 6 additions & 6 deletions src/control/dbgctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
#include "control.h"
#include "rsbuild.h"
#include <errno.h>
#ifdef RS_BUILD_UNISTD_FOUND
#ifdef RS_BUILD_READ_FOUND
#include <unistd.h>
#endif
#ifdef RS_BUILD_FCNTL_FOUND
#include <fcntl.h>
#endif

#if defined(RS_BUILD_UNISTD_FOUND) && defined(RS_BUILD_FCNTL_FOUND)
#if defined(RS_BUILD_READ_FOUND) && defined(RS_BUILD_FCNTL_FOUND)
static int debugControlWantsSave(RSControl *control) {
(void)control;
int ret = 0;
Expand All @@ -50,7 +50,7 @@ static int debugControlWantsSave(RSControl *control) {
#endif

int rsDebugControlCreate(RSControl *control) {
#if defined(RS_BUILD_UNISTD_FOUND) && defined(RS_BUILD_FCNTL_FOUND)
#if defined(RS_BUILD_READ_FOUND) && defined(RS_BUILD_FCNTL_FOUND)
control->destroy = NULL;
control->wantsSave = debugControlWantsSave;
int flags = fcntl(0, F_GETFL);
Expand All @@ -59,11 +59,11 @@ int rsDebugControlCreate(RSControl *control) {

#else
(void)control;
#ifndef RS_BUILD_UNISTD_FOUND
av_log(NULL, AV_LOG_ERROR, "<unistd.h> was not found during compilation\n");
#ifndef RS_BUILD_READ_FOUND
av_log(NULL, AV_LOG_ERROR, "read() was not found during compilation\n");
#endif
#ifndef RS_BUILD_FCNTL_FOUND
av_log(NULL, AV_LOG_ERROR, "<fcntl.h> was not found during compilation\n");
av_log(NULL, AV_LOG_ERROR, "fcntl() was not found during compilation\n");
#endif
return AVERROR(ENOSYS);
#endif
Expand Down
45 changes: 45 additions & 0 deletions src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,52 @@

#include "output.h"
#include "config.h"
#include "rsbuild.h"
#include "util.h"
#include <libavutil/avutil.h>
#include <libavutil/bprint.h>
#include <time.h>
#ifdef RS_BUILD_MKDIR_FOUND
#include <sys/stat.h>
#endif

static int outputDirectory(char *path) {
#ifdef RS_BUILD_MKDIR_FOUND
int ret;
char *slash = strrchr(path, '/');
if (slash == NULL) {
return 0;
}

*slash = '\0';
if ((ret = mkdir(path, 0777)) < 0) {
ret = errno;
}
if (ret == ENOENT) {
if ((ret = outputDirectory(path)) < 0) {
goto error;
}
if ((ret = mkdir(path, 0777)) < 0) {
ret = errno;
}
}
if (ret != 0 && ret != EEXIST) {
ret = AVERROR(ret);
av_log(NULL, AV_LOG_ERROR, "Failed to create directory: %s\n", av_err2str(ret));
goto error;
}

ret = 0;
error:
*slash = '/';
return ret;

#else
(void)path;
av_log(NULL, AV_LOG_WARNING, "mkdir() was not found during compilation\n");
return 0;
#endif
}

int rsOutputCreate(RSOutput *output) {
int ret;
Expand Down Expand Up @@ -51,6 +93,9 @@ int rsOutputCreate(RSOutput *output) {
if ((ret = av_bprint_finalize(&buffer, &output->path)) < 0) {
goto error;
}
if ((ret = outputDirectory(output->path)) < 0) {
goto error;
}

av_log(NULL, AV_LOG_INFO, "Saving video to '%s'...\n", output->path);
if ((ret = avformat_alloc_output_context2(&output->formatCtx, NULL, "mp4",
Expand Down
3 changes: 2 additions & 1 deletion src/rsbuild.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
#cmakedefine RS_BUILD_X11_FOUND
#cmakedefine RS_BUILD_PULSE_FOUND
#cmakedefine RS_BUILD_LIBDRM_FOUND
#cmakedefine RS_BUILD_UNISTD_FOUND
#cmakedefine RS_BUILD_READ_FOUND
#cmakedefine RS_BUILD_FCNTL_FOUND
#cmakedefine RS_BUILD_MKDIR_FOUND

#endif

0 comments on commit 2b3eb35

Please sign in to comment.