Changeset View
Changeset View
Standalone View
Standalone View
src/core/kfileitem.cpp
Show All 35 Lines | |||||
36 | 36 | | |||
37 | #include <klocalizedstring.h> | 37 | #include <klocalizedstring.h> | ||
38 | #include <kdesktopfile.h> | 38 | #include <kdesktopfile.h> | ||
39 | #include <kmountpoint.h> | 39 | #include <kmountpoint.h> | ||
40 | #include <kconfiggroup.h> | 40 | #include <kconfiggroup.h> | ||
41 | #ifndef Q_OS_WIN | 41 | #ifndef Q_OS_WIN | ||
42 | #include <knfsshare.h> | 42 | #include <knfsshare.h> | ||
43 | #include <ksambashare.h> | 43 | #include <ksambashare.h> | ||
44 | #include <sys/xattr.h> | ||||
44 | #endif | 45 | #endif | ||
45 | #include <kfilesystemtype.h> | 46 | #include <kfilesystemtype.h> | ||
46 | 47 | | |||
47 | class KFileItemPrivate : public QSharedData | 48 | class KFileItemPrivate : public QSharedData | ||
48 | { | 49 | { | ||
49 | public: | 50 | public: | ||
50 | KFileItemPrivate(const KIO::UDSEntry &entry, | 51 | KFileItemPrivate(const KIO::UDSEntry &entry, | ||
51 | mode_t mode, mode_t permissions, | 52 | mode_t mode, mode_t permissions, | ||
▲ Show 20 Lines • Show All 1046 Lines • ▼ Show 20 Line(s) | 1079 | { | |||
1098 | // Or if we can't write it - not network transparent | 1099 | // Or if we can't write it - not network transparent | ||
1099 | if (d->m_bIsLocalUrl && !QFileInfo(d->m_url.toLocalFile()).isWritable()) { | 1100 | if (d->m_bIsLocalUrl && !QFileInfo(d->m_url.toLocalFile()).isWritable()) { | ||
1100 | return false; | 1101 | return false; | ||
1101 | } | 1102 | } | ||
1102 | 1103 | | |||
1103 | return true; | 1104 | return true; | ||
1104 | } | 1105 | } | ||
1105 | 1106 | | |||
1107 | #ifndef Q_OS_WIN | ||||
1108 | bool KFileItem::isHiddenNtfs() const | ||||
1109 | { | ||||
1110 | const auto fileName = localPath().toLocal8Bit().constData(); | ||||
1111 | constexpr auto attrName = "system.ntfs_attrib_be"; | ||||
1112 | auto length = getxattr(fileName, attrName, nullptr, 0); | ||||
1113 | if (length <= 0) { | ||||
1114 | return false; | ||||
1115 | } | ||||
1116 | constexpr size_t xattr_size = 1024; | ||||
1117 | char strAttr[xattr_size]; | ||||
1118 | length = getxattr(fileName, attrName, strAttr, xattr_size); | ||||
1119 | if (length <= 0) { | ||||
1120 | return false; | ||||
1121 | } | ||||
1122 | | ||||
1123 | // Decode result to hex string | ||||
1124 | static const auto digits = "0123456789abcdef"; | ||||
1125 | auto hexAttr = new char[length * 2 + 4]; | ||||
1126 | char *c = strAttr, *e = hexAttr; | ||||
1127 | *e++='0'; *e++ = 'x'; | ||||
1128 | for (auto n = 0; n < length; n++, c++) { | ||||
1129 | *e++ = digits[(static_cast<uchar>(*c) >> 4)]; | ||||
1130 | *e++ = digits[(static_cast<uchar>(*c) & 0x0F)]; | ||||
1131 | } | ||||
1132 | *e = '\0'; | ||||
1133 | | ||||
1134 | // Decode hex string to int | ||||
1135 | auto intAttr = static_cast<uint>(strtol(hexAttr, nullptr, 16)); | ||||
1136 | delete[] hexAttr; | ||||
anthonyfieroni: It should be
```
delete[] hexAttr;
``` | |||||
Indeed this should be done in different way, about me std::uint64_t attr; length = getxattr(fileName, attrName, &attr, sizeof attr); if (length <= 0) { return false; } anthonyfieroni: Indeed this should be done in different way, about me
```
std::uint64_t attr;
length = getxattr… | |||||
I wish your code to work, but it doesn't. I took an inspiration from attr: http://git.savannah.nongnu.org/cgit/attr.git/tree/tools/getfattr.c#n235 and http://git.savannah.nongnu.org/cgit/attr.git/tree/tools/getfattr.c#n169. rominf: I wish your code to work, but it doesn't. I took an inspiration from `attr`: http://git. | |||||
1137 | | ||||
1138 | constexpr auto FILE_ATTRIBUTE_HIDDEN = 0x2u; | ||||
1139 | return static_cast<bool>(intAttr & FILE_ATTRIBUTE_HIDDEN); | ||||
1140 | } | ||||
1141 | #endif | ||||
1142 | | ||||
1106 | bool KFileItem::isHidden() const | 1143 | bool KFileItem::isHidden() const | ||
1107 | { | 1144 | { | ||
1108 | if (!d) { | 1145 | if (!d) { | ||
1109 | return false; | 1146 | return false; | ||
1110 | } | 1147 | } | ||
1111 | 1148 | | |||
1112 | // The kioslave can specify explicitly that a file is hidden or shown | 1149 | // The kioslave can specify explicitly that a file is hidden or shown | ||
1113 | if (d->m_hidden != KFileItemPrivate::Auto) { | 1150 | if (d->m_hidden != KFileItemPrivate::Auto) { | ||
1114 | return d->m_hidden == KFileItemPrivate::Hidden; | 1151 | return d->m_hidden == KFileItemPrivate::Hidden; | ||
1115 | } | 1152 | } | ||
1116 | 1153 | | |||
1117 | // Prefer the filename that is part of the URL, in case the display name is different. | 1154 | // Prefer the filename that is part of the URL, in case the display name is different. | ||
1118 | QString fileName = d->m_url.fileName(); | 1155 | QString fileName = d->m_url.fileName(); | ||
1119 | if (fileName.isEmpty()) { // e.g. "trash:/" | 1156 | if (fileName.isEmpty()) { // e.g. "trash:/" | ||
1120 | fileName = d->m_strName; | 1157 | fileName = d->m_strName; | ||
1121 | } | 1158 | } | ||
1122 | return fileName.length() > 1 && fileName[0] == '.'; // Just "." is current directory, not hidden. | 1159 | auto result = fileName.length() > 1 && fileName[0] == '.'; // Just "." is current directory, not hidden. | ||
1160 | #ifndef Q_OS_WIN | ||||
1161 | result = result || isHiddenNtfs(); | ||||
1162 | #endif | ||||
1163 | return result; | ||||
1123 | } | 1164 | } | ||
1124 | 1165 | | |||
1125 | void KFileItem::setHidden() | 1166 | void KFileItem::setHidden() | ||
1126 | { | 1167 | { | ||
1127 | if (d) { | 1168 | if (d) { | ||
1128 | d->m_hidden = KFileItemPrivate::Hidden; | 1169 | d->m_hidden = KFileItemPrivate::Hidden; | ||
1129 | } | 1170 | } | ||
1130 | } | 1171 | } | ||
▲ Show 20 Lines • Show All 449 Lines • Show Last 20 Lines |
It should be