Skip to content
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
53 changes: 51 additions & 2 deletions src/dfm-io/dfm-io/doperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

#include <QFile>
#include <QTextStream>
#include <QDateTime>

Check warning on line 11 in src/dfm-io/dfm-io/doperator.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDateTime> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 11 in src/dfm-io/dfm-io/doperator.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDateTime> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <glib/gstdio.h>

Check warning on line 13 in src/dfm-io/dfm-io/doperator.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <glib/gstdio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 13 in src/dfm-io/dfm-io/doperator.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <glib/gstdio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <errno.h>

Check warning on line 14 in src/dfm-io/dfm-io/doperator.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <errno.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 14 in src/dfm-io/dfm-io/doperator.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <errno.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

USING_IO_NAMESPACE

Expand Down Expand Up @@ -40,6 +41,54 @@
}
}

void DOperatorPrivate::setErrorFromErrno(int errnoValue)
{
DFMIOErrorCode errorCode;
switch (errnoValue) {
case EACCES:
case EPERM:
errorCode = DFM_IO_ERROR_PERMISSION_DENIED;
break;
case ENOENT:
errorCode = DFM_IO_ERROR_NOT_FOUND;
break;
case EEXIST:
case ENOTEMPTY:
errorCode = DFM_IO_ERROR_EXISTS;
break;
case EISDIR:
errorCode = DFM_IO_ERROR_IS_DIRECTORY;
break;
case ENOTDIR:
errorCode = DFM_IO_ERROR_NOT_DIRECTORY;
break;
case EROFS:
errorCode = DFM_IO_ERROR_READ_ONLY;
break;
case ENOSPC:
errorCode = DFM_IO_ERROR_NO_SPACE;
break;
case ENAMETOOLONG:
errorCode = DFM_IO_ERROR_FILENAME_TOO_LONG;
break;
case EINVAL:
errorCode = DFM_IO_ERROR_INVALID_ARGUMENT;
break;
case EBUSY:
errorCode = DFM_IO_ERROR_BUSY;
break;
case EXDEV:
// Cross-device rename not supported by g_rename
errorCode = DFM_IO_ERROR_NOT_SUPPORTED;
break;
default:
errorCode = DFM_IO_ERROR_FAILED;
break;
}

error.setCode(errorCode);
}

GFile *DOperatorPrivate::makeGFile(const QUrl &url)
{
return DLocalHelper::createGFile(url);
Expand Down Expand Up @@ -215,9 +264,9 @@

const bool ret = g_rename(fromStr.c_str(), toStr.c_str()) == 0;

// set error info
// set error info based on errno
if (!ret)
d->error.setCode(DFM_IO_ERROR_PERMISSION_DENIED);
d->setErrorFromErrno(errno);

return ret;
}
Expand Down
1 change: 1 addition & 0 deletions src/dfm-io/dfm-io/private/doperator_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class DOperatorPrivate
virtual ~DOperatorPrivate();

void setErrorFromGError(GError *gerror);
void setErrorFromErrno(int errnoValue);
GFile *makeGFile(const QUrl &url);
void checkAndResetCancel();

Expand Down
Loading