Skip to content

Commit 7440123

Browse files
committed
Fixed setFilePermissions
1 parent 4888223 commit 7440123

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

src/wsjcpp_core.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ WsjcppFilePermissions::WsjcppFilePermissions(
5757
WsjcppFilePermissions::WsjcppFilePermissions(uint16_t nFilePermission) {
5858

5959
// owner
60-
m_bOwnerReadFlag = nFilePermission & 0x0400 != 0x0;
61-
m_bOwnerWriteFlag = nFilePermission & 0x0200 != 0x0;
62-
m_bOwnerExecuteFlag = nFilePermission & 0x0100 != 0x0;
60+
m_bOwnerReadFlag = nFilePermission & 0x0400;
61+
m_bOwnerWriteFlag = nFilePermission & 0x0200;
62+
m_bOwnerExecuteFlag = nFilePermission & 0x0100;
6363

6464
// group
65-
m_bGroupReadFlag = nFilePermission & 0x0040 != 0x0;
66-
m_bGroupWriteFlag = nFilePermission & 0x0020 != 0x0;
67-
m_bGroupExecuteFlag = nFilePermission & 0x0010 != 0x0;
65+
m_bGroupReadFlag = nFilePermission & 0x0040;
66+
m_bGroupWriteFlag = nFilePermission & 0x0020;
67+
m_bGroupExecuteFlag = nFilePermission & 0x0010;
6868

6969
// for other
70-
m_bOtherReadFlag = nFilePermission & 0x0004 != 0x0;
71-
m_bOtherWriteFlag = nFilePermission & 0x0002 != 0x0;
72-
m_bOtherExecuteFlag = nFilePermission & 0x0001 != 0x0;
70+
m_bOtherReadFlag = nFilePermission & 0x0004;
71+
m_bOtherWriteFlag = nFilePermission & 0x0002;
72+
m_bOtherExecuteFlag = nFilePermission & 0x0001;
7373
}
7474

7575
// ---------------------------------------------------------------------
@@ -996,8 +996,8 @@ bool WsjcppCore::setFilePermissions(const std::string& sFilePath, const WsjcppFi
996996

997997
// owner
998998
m |= filePermissions.getOwnerReadFlag() ? S_IRUSR : 0x0;
999-
m |= filePermissions.getOwnerWriteFlag() & S_IWUSR != 0x0;
1000-
m |= filePermissions.getOwnerExecuteFlag() & S_IXUSR != 0x0;
999+
m |= filePermissions.getOwnerWriteFlag() ? S_IWUSR : 0x0;
1000+
m |= filePermissions.getOwnerExecuteFlag() ? S_IXUSR : 0x0;
10011001

10021002
// group
10031003
m |= filePermissions.getGroupReadFlag() ? S_IRGRP : 0x0;

unit-tests.wsjcpp/data/file_permissions/file2

Whitespace-only changes.

unit-tests.wsjcpp/data/file_permissions/file3

Whitespace-only changes.

unit-tests.wsjcpp/src/unit_test_file_permissions.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,26 +181,33 @@ void UnitTestFilePermissions::executeTest() {
181181
compare("file_perm (11) other write", fp2.getOtherWriteFlag(), true);
182182
compare("file_perm (11) other execute", fp2.getOtherExecuteFlag(), true);
183183

184-
WsjcppFilePermissions fp3(0x0777);
185-
compare("file_perm (12) toString", fp3.toString(), "-rwxrwxrwx");
186-
compare("file_perm (12) toUInt16", fp3.toUInt16(), 0x0777);
184+
WsjcppFilePermissions fp3(0x764);
185+
compare("file_perm (12) toString", fp3.toString(), "-rwxrw-r--");
186+
compare("file_perm (12) toUInt16", fp3.toUInt16(), 0x0764);
187187
compare("file_perm (12) owner read", fp3.getOwnerReadFlag(), true);
188188
compare("file_perm (12) owner write", fp3.getOwnerWriteFlag(), true);
189189
compare("file_perm (12) owner execute", fp3.getOwnerExecuteFlag(), true);
190190
compare("file_perm (12) group read", fp3.getGroupReadFlag(), true);
191191
compare("file_perm (12) group write", fp3.getGroupWriteFlag(), true);
192-
compare("file_perm (12) group execute", fp3.getGroupExecuteFlag(), true);
192+
compare("file_perm (12) group execute", fp3.getGroupExecuteFlag(), false);
193193
compare("file_perm (12) other read", fp3.getOtherReadFlag(), true);
194-
compare("file_perm (12) other write", fp3.getOtherWriteFlag(), true);
195-
compare("file_perm (12) other execute", fp3.getOtherExecuteFlag(), true);
194+
compare("file_perm (12) other write", fp3.getOtherWriteFlag(), false);
195+
compare("file_perm (12) other execute", fp3.getOtherExecuteFlag(), false);
196196

197197
{
198-
WsjcppFilePermissions fp4(0x0);
199198
std::string sError;
200-
bool bRes1 = WsjcppCore::getFilePermissions("./data/file_permissions/file1", fp4, sError);
201-
compare("file_perm (13) getFilePermissions", bRes1, true);
202-
compare("file_perm (13) toString", fp4.toString(), "-rw----r--");
203-
compare("file_perm (13) toUInt16", fp4.toUInt16(), 0x0604);
199+
WsjcppFilePermissions fp4_(0x0604);
200+
compare("file_perm (13b) toString", fp4_.toString(), "-rw----r--");
201+
compare("file_perm (13b) toUInt16", fp4_.toUInt16(), 0x0604);
202+
bool bRes1 = WsjcppCore::setFilePermissions("./data/file_permissions/file1", fp4_, sError);
203+
compare("file_perm (13b) setFilePermissions", bRes1, true);
204+
205+
206+
WsjcppFilePermissions fp4(0x0);
207+
bool bRes2 = WsjcppCore::getFilePermissions("./data/file_permissions/file1", fp4, sError);
208+
compare("file_perm (13a) getFilePermissions", bRes2, true);
209+
compare("file_perm (13a) toString", fp4.toString(), "-rw----r--");
210+
compare("file_perm (13a) toUInt16", fp4.toUInt16(), 0x604);
204211
}
205212

206213
{

0 commit comments

Comments
 (0)