Browse Source

Give appropriately scary name to dangerous function

"isPathWritable" didn't convey really well the meaning of "let's try to open it, wipe everything the hell out, and see if it worked"
pull/1551/head
tux3 10 years ago
parent
commit
542cae85d3
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
  1. 4
      src/chatlog/content/filetransferwidget.cpp
  2. 2
      src/nexus.cpp
  3. 2
      src/nexus.h
  4. 4
      src/widget/form/profileform.cpp

4
src/chatlog/content/filetransferwidget.cpp

@ -118,7 +118,7 @@ void FileTransferWidget::autoAcceptTransfer(const QString &path) @@ -118,7 +118,7 @@ void FileTransferWidget::autoAcceptTransfer(const QString &path)
//Do not automatically accept the file-transfer if the path is not writable.
//The user can still accept it manually.
if (Nexus::isFilePathWritable(filepath))
if (Nexus::tryRemoveFile(filepath))
Core::getInstance()->acceptFileRecvRequest(fileInfo.friendId, fileInfo.fileNum, filepath);
else
qDebug() << "Warning: Cannot write to " << filepath;
@ -130,7 +130,7 @@ void FileTransferWidget::acceptTransfer(const QString &filepath) @@ -130,7 +130,7 @@ void FileTransferWidget::acceptTransfer(const QString &filepath)
return;
//test if writable
if(!Nexus::isFilePathWritable(filepath))
if(!Nexus::tryRemoveFile(filepath))
{
QMessageBox::warning(0,
tr("Location not writable","Title of permissions popup"),

2
src/nexus.cpp

@ -180,7 +180,7 @@ QString Nexus::getSupportedImageFilter() @@ -180,7 +180,7 @@ QString Nexus::getSupportedImageFilter()
return tr("Images (%1)", "filetype filter").arg(res.left(res.size()-1));
}
bool Nexus::isFilePathWritable(const QString& filepath)
bool Nexus::tryRemoveFile(const QString& filepath)
{
QFile tmp(filepath);
bool writable = tmp.open(QIODevice::WriteOnly);

2
src/nexus.h

@ -23,7 +23,7 @@ public: @@ -23,7 +23,7 @@ public:
static AndroidGUI* getAndroidGUI(); ///< Will return 0 if not started
static Widget* getDesktopGUI(); ///< Will return 0 if not started
static QString getSupportedImageFilter();
static bool isFilePathWritable(const QString& filepath); // WARNING: Tests by brute force, i.e. removes the file in question
static bool tryRemoveFile(const QString& filepath); ///< Dangerous way to find out if a path is writable
private:
explicit Nexus(QObject *parent = 0);

4
src/widget/form/profileform.cpp

@ -278,7 +278,7 @@ void ProfileForm::onExportClicked() @@ -278,7 +278,7 @@ void ProfileForm::onExportClicked()
tr("Tox save file (*.tox)", "save dialog filter"));
if (!path.isEmpty())
{
if (!Nexus::isFilePathWritable(path))
if (!Nexus::tryRemoveFile(path))
{
GUI::showWarning(tr("Location not writable","Title of permissions popup"), tr("You do not have permission to write that location. Choose another, or cancel the save dialog.", "text of permissions popup"));
return;
@ -386,7 +386,7 @@ void ProfileForm::on_saveQr_clicked() @@ -386,7 +386,7 @@ void ProfileForm::on_saveQr_clicked()
tr("Save QrCode (*.png)", "save dialog filter"));
if (!path.isEmpty())
{
if (!Nexus::isFilePathWritable(path))
if (!Nexus::tryRemoveFile(path))
{
GUI::showWarning(tr("Location not writable","Title of permissions popup"), tr("You do not have permission to write that location. Choose another, or cancel the save dialog.", "text of permissions popup"));
return;

Loading…
Cancel
Save