{"size": 1247, "ext": "js", "max_stars_repo_path": "src/io-paths/target-path.js", "max_stars_repo_name": "tjohnston-softdev/maze-graph-pathfinding", "max_stars_repo_stars_event_min_datetime": "2021-03-24T11:12:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-24T11:12:19.000Z", "max_issues_repo_path": "src/io-paths/target-path.js", "max_issues_repo_name": "tjohnston-softdev/maze-graph-pathfinding", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/io-paths/target-path.js", "max_forks_repo_name": "tjohnston-softdev/maze-graph-pathfinding", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.1086956522, "max_line_length": 86, "alphanum_fraction": 0.7353648757}
const ora = require("ora-classic");
const spinText = require("../common/sub-interface/spin-text/st-io-paths");
const fsPathExist = require("../common/sub-files/fs-path-exist");

/*
	* This checks whether the target output file path is available.
	* Used for conversion and 'create-image-config' commands.
	* Unlike most io-paths, an existing file can be replaced.
*/


function verifyTargetPathSafe(resOutputPath, replaceAllowed, ioPathCallback)
{
	var pathCheckSpinner = ora(spinText.targetPathProg).start();
	
	fsPathExist.checkPathExists(resOutputPath, function (pathExistError, pathExistResult)
	{
		if (pathExistResult === true && replaceAllowed === true)
		{
			// File already exists. Will be overwritten.
			pathCheckSpinner.succeed(spinText.targetPathComp);
			return ioPathCallback(null, true);
		}
		else if (pathExistResult === true)
		{
			// File already exists. Overwrite not allowed.
			pathCheckSpinner.fail(spinText.targetPathExists);
			return ioPathCallback(new Error(spinText.targetPathExists), null);
		}
		else
		{
			// File does not exist. Can be created.
			pathCheckSpinner.succeed(spinText.targetPathComp);
			return ioPathCallback(null, true);
		}
		
	});
	
}



module.exports =
{
	verifySafe: verifyTargetPathSafe
};