Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Fix: avoid deleting project folder #312

Merged
merged 3 commits into from
Jun 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions qml/Application.qml
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,21 @@ ApplicationWindow {
Component.onCompleted: codeModel.setOptimizeCode(checked)
}


MessageDialog {
id: alertMessageDialog
icon: StandardIcon.Warning
function pop(text)
{
this.text = text
this.open()
}
onAccepted:
{
this.text = ""
}
}

Settings {
id: appSettings
property alias gasEstimation: gasEstimationAction.checked
Expand Down
11 changes: 9 additions & 2 deletions qml/ProjectModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,15 @@ Item {
id: newFolderDialog
visible: false
onAccepted: {
fileIo.makeDir(newFolderDialog.path)
folderAdded(newFolderDialog.path)
if (!fileIo.dirExists(newFolderDialog.path))
{
if (fileIo.makeDir(newFolderDialog.path))
folderAdded(newFolderDialog.path)
else
alertMessageDialog.pop(qsTr("Error while creating folder"))
}
else
alertMessageDialog.pop(qsTr("Directory already exists"))
}
}

Expand Down
64 changes: 58 additions & 6 deletions qml/js/NetworkDeployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,37 @@ function copyFiles(path, target)
if (path === projectModel.projectPath && dirs[i].fileName === deploymentDialog.packageStep.folderName)
continue
var deployDir = target + dirs[i].fileName + "/"
fileIo.makeDir(deployDir)
copyFiles(dirs[i].path, deployDir)
if (!fileIo.dirExists(deployDir))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This process now fails silently if the directory already exists.

{
if (fileIo.makeDir(deployDir))
{
var ret = copyFiles(dirs[i].path, deployDir)
if (!ret.success)
return ret
}
else
{
var mes = qsTr('Unable to create package directory. Cannot create folder ') + deployDir
return {
success: false,
message: mes
}
}
}
else
{
var mes = qsTr("Unable to create directory. Directory already exists ") + deployDir
return {
success: false,
message: mes
}
}
}
}
return {
success: true,
message: ''
}
}

function packageDapp(addresses)
Expand All @@ -298,10 +325,35 @@ function packageDapp(addresses)

projectModel.deploymentDir = deploymentDir;
fileIo.deleteDir(deploymentDir)
fileIo.makeDir(deploymentDir);
var wwwFolder = deploymentDir + "/www/"
fileIo.makeDir(wwwFolder);
copyFiles(projectModel.projectPath, wwwFolder)
if (fileIo.makeDir(deploymentDir))
{
var wwwFolder = deploymentDir + "/www/"
if (fileIo.makeDir(wwwFolder))
{
var result = copyFiles(projectModel.projectPath, wwwFolder)
if (!result.success)
{
console.log(result.message)
deploymentError(result.message)
return
}
}
else
{
var mes = qsTr('cannot create ') + deploymentDir
console.log(mes)
deploymentError(mes)
return
}
}
else
{
var mes = qsTr('cannot create ') + wwwFolder
console.log(mes)
deploymementError(mes)
return
}

//write deployment js
var deploymentJs =
"// Autogenerated by Mix\n" +
Expand Down
26 changes: 23 additions & 3 deletions qml/js/ProjectModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,16 @@ function doCreateProject(title, path) {
closeProject(function() {
console.log("Creating project " + title + " at " + path);
var dirPath = path + "/" + title
fileIo.makeDir(dirPath);
if (fileIo.dirExists(dirPath))
{
alertMessageDialog.pop(qsTr("Directory already exists. Unable to continue."))
return
}
if (!fileIo.makeDir(dirPath))
{
console.log('Cannot create project folder. Project not created')
return
}
var projectFile = dirPath + "/" + projectFileName;
var indexFile = "index.html";
var contractsFile = "contract.sol";
Expand Down Expand Up @@ -340,7 +349,11 @@ function generateFileName(name, extension) {
function regenerateCompilationResult()
{
fileIo.deleteDir(compilationFolder)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that safe to delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. This function is called when mix is autogenerating the compilation result. this will never delete content added by the user.

fileIo.makeDir(compilationFolder)
if (!fileIo.makeDir(compilationFolder))
{
console.log("compilation folder not created")
return
}
var ctrJson = {}
for (var c in codeModel.contracts)
{
Expand All @@ -355,7 +368,14 @@ function regenerateCompilationResult()
function saveContractCompilationResult(documentId)
{
if (!fileIo.dirExists(compilationFolder))
fileIo.makeDir(compilationFolder)
{
if (!fileIo.makeDir(compilationFolder))
{
console.log("Contract compilation result not created.")
return
}
}

var date = new Date()
var ret = "/*\nGenerated by Mix\n" + date.toString() + "\n*/\n\n"
var newCompilationResult = false
Expand Down
6 changes: 4 additions & 2 deletions src/FileIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,20 @@ QString FileIo::pathFromUrl(QString const& _url)
return path;
}

void FileIo::makeDir(QString const& _url)
bool FileIo::makeDir(QString const& _url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change the semantics of this function, you should also change how it is used.
In most places where this is used, the assumption is that the directory can be used afterwards and is clear.

{
try
{
QDir dirPath(pathFromUrl(_url));
if (dirPath.exists())
dirPath.removeRecursively();
return false;
dirPath.mkpath(dirPath.path());
return true;
}
catch (...)
{
manageException();
return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/FileIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class FileIo: public QObject
public:
FileIo();
/// Create a directory if it does not exist. Signals on failure.
Q_INVOKABLE void makeDir(QString const& _url);
Q_INVOKABLE bool makeDir(QString const& _url);
/// Read file contents to a string. Signals on failure.
Q_INVOKABLE QString readFile(QString const& _url);
/// Returns file size
Expand Down