From 4ce2555a6563939f95991621facc7ff4b9f27d1d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Dec 2013 15:32:39 +1100 Subject: [PATCH] DataFlash: don't try to create a directory that exists this is an attempt to avoid microSD card corruption. The most common corruption is two 'logs' directories, which may indicate an issue with trying to create it a 2nd time. --- libraries/DataFlash/DataFlash_File.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/DataFlash/DataFlash_File.cpp b/libraries/DataFlash/DataFlash_File.cpp index e1c2571992..0a1b4cb387 100644 --- a/libraries/DataFlash/DataFlash_File.cpp +++ b/libraries/DataFlash/DataFlash_File.cpp @@ -50,8 +50,12 @@ void DataFlash_File::Init(void) { // create the log directory if need be int ret; - ret = mkdir(_log_directory, 0777); - if (ret == -1 && errno != EEXIST) { + struct stat st; + ret = stat(_log_directory, &st); + if (ret == -1) { + ret = mkdir(_log_directory, 0777); + } + if (ret == -1) { hal.console->printf("Failed to create log directory %s", _log_directory); return; }