-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure export directory paths are sane, absolute paths all the time
- Loading branch information
Showing
2 changed files
with
30 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2016-2017 Matthias Klumpp <[email protected]> | ||
* Copyright (C) 2016-2021 Matthias Klumpp <[email protected]> | ||
* | ||
* Licensed under the GNU Lesser General Public License Version 3 | ||
* | ||
|
@@ -54,7 +54,7 @@ Application Options: | |
--force Force action. | ||
-w|--workspace Define the workspace location. | ||
-c|--config Use the given configuration file. | ||
-e|--exportDir Directory to export data to."; | ||
--export-dir Override the workspace root export directory."; | ||
|
||
version (unittest) { | ||
void main () {} | ||
|
@@ -96,7 +96,7 @@ void main(string[] args) | |
bool showVersion; | ||
bool forceAction; | ||
string wdir; | ||
string edir; | ||
string exportDir; | ||
string configFname; | ||
|
||
// parse command-line options | ||
|
@@ -108,7 +108,7 @@ void main(string[] args) | |
"force", &forceAction, | ||
"workspace|w", &wdir, | ||
"config|c", &configFname, | ||
"exportDir|e", &edir); | ||
"export-dir", &exportDir); | ||
} catch (Exception e) { | ||
writeln ("Unable to parse parameters: ", e.msg); | ||
exit (1); | ||
|
@@ -143,7 +143,7 @@ void main(string[] args) | |
} | ||
|
||
try { | ||
conf.loadFromFile (configFname, wdir, edir); | ||
conf.loadFromFile (configFname, wdir, exportDir); | ||
} catch (Exception e) { | ||
writefln ("Unable to load configuration: %s", e.msg); | ||
exit (4); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2016-2020 Matthias Klumpp <[email protected]> | ||
* Copyright (C) 2016-2021 Matthias Klumpp <[email protected]> | ||
* | ||
* Licensed under the GNU Lesser General Public License Version 3 | ||
* | ||
|
@@ -22,7 +22,7 @@ module asgen.config; | |
import std.stdio; | ||
import std.array; | ||
import std.string : format, toLower; | ||
import std.path : dirName, buildPath, buildNormalizedPath; | ||
import std.path : dirName, buildPath, buildNormalizedPath, isAbsolute, absolutePath; | ||
import std.conv : to; | ||
import std.json; | ||
import std.typecons; | ||
|
@@ -289,6 +289,8 @@ public: | |
// allow overriding the workspace location | ||
if (!enforcedWorkspaceDir.empty) | ||
workspaceDir = enforcedWorkspaceDir; | ||
if (!workspaceDir.isAbsolute) | ||
workspaceDir = workspaceDir.absolutePath; | ||
|
||
this.projectName = "Unknown"; | ||
if ("ProjectName" in root) | ||
|
@@ -304,18 +306,22 @@ public: | |
if ("HtmlBaseUrl" in root) | ||
this.htmlBaseUrl = root["HtmlBaseUrl"].str; | ||
|
||
// set the default export directory locations, allow people to override them in the config | ||
exportDir = buildPath (workspaceDir, "export"); | ||
|
||
// allow overriding the export location | ||
if (!enforcedExportDir.empty) | ||
// set root export directory | ||
if (enforcedExportDir.empty) { | ||
exportDir = buildPath (workspaceDir, "export"); | ||
} else { | ||
exportDir = enforcedExportDir; | ||
logInfo ("Using data export directory root from the command-line: %s", exportDir); | ||
} | ||
if (!exportDir.isAbsolute) | ||
exportDir = exportDir.absolutePath; | ||
|
||
mediaExportDir = buildPath (exportDir, "media"); | ||
dataExportDir = buildPath (exportDir, "data"); | ||
hintsExportDir = buildPath (exportDir, "hints"); | ||
htmlExportDir = buildPath (exportDir, "html"); | ||
auto extraMetainfoDir = buildPath (workspaceDir, "extra-metainfo"); | ||
// set the default export directory locations, allow people to override them in the config | ||
// (we convert the relative to absolute paths later) | ||
mediaExportDir = "media"; | ||
dataExportDir = "data"; | ||
hintsExportDir = "hints"; | ||
htmlExportDir = "html"; | ||
|
||
if ("ExportDirs" in root) { | ||
auto edirs = root["ExportDirs"].object; | ||
|
@@ -339,7 +345,14 @@ public: | |
} | ||
} | ||
|
||
// convert export directory paths to absolute paths if necessary | ||
mediaExportDir = mediaExportDir.isAbsolute? mediaExportDir : buildNormalizedPath (exportDir, mediaExportDir); | ||
dataExportDir = dataExportDir.isAbsolute? dataExportDir : buildNormalizedPath (exportDir, dataExportDir); | ||
hintsExportDir = hintsExportDir.isAbsolute? hintsExportDir : buildNormalizedPath (exportDir, hintsExportDir); | ||
htmlExportDir = htmlExportDir.isAbsolute? htmlExportDir : buildNormalizedPath (exportDir, htmlExportDir); | ||
|
||
// a place where external metainfo data can be injected | ||
auto extraMetainfoDir = buildPath (workspaceDir, "extra-metainfo"); | ||
if ("ExtraMetainfoDir" in root) | ||
extraMetainfoDir = root["ExtraMetainfoDir"].str; | ||
|
||
|