[Avida-cvs] [avida-svn] r686 - in development/source: analyze main tools
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Tue May 16 13:37:44 PDT 2006
Author: brysonda
Date: 2006-05-16 16:37:44 -0400 (Tue, 16 May 2006)
New Revision: 686
Modified:
development/source/analyze/cAnalyze.cc
development/source/main/cWorld.cc
development/source/tools/cDataFileManager.cc
development/source/tools/cDataFileManager.h
Log:
Fix various analyze mode commands that relied upon directory creation. Directories were being created outside of the data directory. As a result, when attempting to open a file the operations would fail.
The solution enhances cDataFileManager to support arbitrary paths within the data directory. Upon opening a new file handle, cDataFileManager will create the directory structure as necessary.
Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc 2006-05-16 20:02:06 UTC (rev 685)
+++ development/source/analyze/cAnalyze.cc 2006-05-16 20:37:44 UTC (rev 686)
@@ -7191,8 +7191,7 @@
/////////////////// Private Methods ///////////////////////////
-cString cAnalyze::PopDirectory(cString & in_string,
- const cString & default_dir)
+cString cAnalyze::PopDirectory(cString& in_string, const cString& default_dir)
{
// Determing the directory name
cString directory(default_dir);
@@ -7204,17 +7203,6 @@
directory += '/';
}
- // Make sure the directory exists.
- FILE *fp = fopen (directory, "r");
- if ( fp == 0 ) {
- if ( errno == ENOENT ) {
- cerr << "Directory '" << directory << "' does not exist. Creating..." << endl;
- if (mkdir(directory, (S_IRWXU|S_IRWXG|S_IRWXO)))
- cerr << " Error creating '" << directory << "'" << endl;
- }
- else cerr << " Error opening '" << directory << "'" << endl;
- }
-
return directory;
}
Modified: development/source/main/cWorld.cc
===================================================================
--- development/source/main/cWorld.cc 2006-05-16 20:02:06 UTC (rev 685)
+++ development/source/main/cWorld.cc 2006-05-16 20:37:44 UTC (rev 686)
@@ -72,7 +72,6 @@
m_conf->DATA_DIR.Set(dir);
}
m_data_mgr = new cDataFileManager(dir);
- cTools::MkDir(dir + "archive", true);
m_class_mgr = new cClassificationManager(this);
m_env = new cEnvironment(this);
Modified: development/source/tools/cDataFileManager.cc
===================================================================
--- development/source/tools/cDataFileManager.cc 2006-05-16 20:02:06 UTC (rev 685)
+++ development/source/tools/cDataFileManager.cc 2006-05-16 20:37:44 UTC (rev 686)
@@ -10,6 +10,8 @@
#include "cDataFileManager.h"
+#include "cTools.h"
+
using namespace std;
@@ -29,6 +31,24 @@
// If it hasn't been found, create it...
if (!m_datafiles.Find(name, found_file)) {
+ // Create directory structure, as necessary
+ int i = 0;
+ while (i < name.GetSize()) {
+ int d = name.Find('/', i);
+ int b = name.Find('\\', i);
+
+ // If a backslash is found, and earlier then next forward slash, use it instead
+ if (b != -1 && b < d) d = b;
+
+ // Exit if neither slash is found
+ if (d == -1) break;
+
+ // If directory name is not null
+ if (d - i > 0) cTools::MkDir(m_target_dir + name.Substring(0, d - i), false);
+
+ // Adjust next directory name starting point
+ i = d + 1;
+ }
cString filename = m_target_dir + name;
found_file = new cDataFile(filename);
m_datafiles.Add(name, found_file);
Modified: development/source/tools/cDataFileManager.h
===================================================================
--- development/source/tools/cDataFileManager.h 2006-05-16 20:02:06 UTC (rev 685)
+++ development/source/tools/cDataFileManager.h 2006-05-16 20:37:44 UTC (rev 686)
@@ -37,8 +37,6 @@
cString m_target_dir;
tDictionary<cDataFile*> m_datafiles;
- cDataFile* InternalFind(const cString& name);
-
cDataFileManager(const cDataFileManager&); // @not_implemented
cDataFileManager& operator=(const cDataFileManager&); // @not_implemented
More information about the Avida-cvs
mailing list