Skip to content

Commit

Permalink
Add pathIsWritable test in codeeditorbackend.
Browse files Browse the repository at this point in the history
  • Loading branch information
andeplane committed May 12, 2017
1 parent 25ec886 commit d13c6d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/codeeditorbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ bool CodeEditorBackend::fileExists(QString path)
return info.exists();
}

bool CodeEditorBackend::filePathIsWritable(QString filePath)
{
filePath.replace("file://", "");
QDir dir = QFileInfo(filePath).absoluteDir();
QString tmpFile = QDir::cleanPath(dir.absolutePath() + QDir::separator() + "tmp1337");
QFile f(tmpFile);
if(!f.open(QIODevice::WriteOnly)) {
return false;
}
f.close();
dir.remove(tmpFile);
return true;
}

QString CodeEditorBackend::cleanPath(QString path)
{
return "file://"+QUrl(path).toLocalFile();
Expand Down
1 change: 1 addition & 0 deletions src/codeeditorbackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CodeEditorBackend : public QQuickItem

QString folder() const;
Q_INVOKABLE bool fileExists(QString path);
Q_INVOKABLE bool filePathIsWritable(QString filePath);
Q_INVOKABLE QString cleanPath(QString path);
Q_INVOKABLE QVariantMap getParameters(QUrl path);
signals:
Expand Down

0 comments on commit d13c6d4

Please sign in to comment.