Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File permission transfer #155

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class Protocol {
/// 1 byte for cmd, 2 bytes for file-name length, Max size of filename, 5
/// variants(seq-id, data-size, offset, file-size, permission), 1 byte for
/// flag, 10 bytes prev seq-id
static constexpr int64_t kMaxHeader = 1 + 2 + PATH_MAX + 5 * 10 + 2 + 1 + 10;
static constexpr int64_t kMaxHeader = 1 + 2 + PATH_MAX + 5 * 10 + 1 + 10;
/// min number of bytes that must be send to unblock receiver
static constexpr int64_t kMinBufLength = 256;
/// max size of done command encoding(1 byte for cmd, 1 for status, 10 for
Expand Down
1 change: 1 addition & 0 deletions build/travis_osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export PATH=/usr/local/opt/openssl/bin:$CMAKE_BIN_DIR:$HOME/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/opt/openssl/lib:$HOME/lib:$LD_LIBRARY_PATH
export OPENSSL_ROOT_DIR=/usr/local/opt/openssl
export CMAKE_PREFIX_PATH=$HOME
export WDT_TEST_PERMISSION=0
openssl version -a
wget https://www.cmake.org/files/v3.6/$CMAKE_BASE.tar.gz
tar xfz $CMAKE_BASE.tar.gz
Expand Down
22 changes: 22 additions & 0 deletions test/FileReaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ class RandomFile {
int64_t getSize() const {
return fileSize_;
}
int32_t getPermission() {
if (permission_ == -1) {
struct stat fileStat;
if (stat(fileName_.c_str(), &fileStat) != 0) {
WLOG(ERROR) << "Error when calling stat()";
return -1;
}
permission_ = fileStat.st_mode & (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU |
S_IRWXG | S_IRWXO);
}
return permission_;
}
const string& getFileName() const {
return fileName_;
}
Expand All @@ -65,6 +77,7 @@ class RandomFile {

private:
int64_t fileSize_{-1};
int32_t permission_{-1};
string fileName_;
SourceMetaData* metaData_{nullptr};
};
Expand Down Expand Up @@ -98,6 +111,10 @@ void testReadSize(int64_t fileSize, ByteSource& byteSource) {
EXPECT_EQ(totalSizeRead, fileSize);
}

void testReadPermission(int32_t permission, ByteSource& byteSource) {
EXPECT_EQ(permission, byteSource.getMetaData().permission);
}

void testFileRead(const WdtOptions& options, int64_t fileSize,
bool directReads) {
RandomFile file(fileSize);
Expand Down Expand Up @@ -158,6 +175,7 @@ TEST(FileByteSource, FILEINFO_ODIRECT) {
ThreadCtx threadCtx(options, true);
auto byteSource = Q.getNextSource(&threadCtx, code);
testReadSize(sizeToRead, *byteSource);
testReadPermission(file.getPermission(), *byteSource);
}

TEST(FileByteSource, MULTIPLEFILES_ODIRECT) {
Expand Down Expand Up @@ -191,6 +209,7 @@ TEST(FileByteSource, MULTIPLEFILES_ODIRECT) {
break;
}
testReadSize(sizeToRead, *byteSource);
testReadPermission(randFiles[fileNumber].getPermission(), *byteSource);
++fileNumber;
}
EXPECT_EQ(fileNumber, numFiles);
Expand Down Expand Up @@ -219,13 +238,16 @@ TEST(FileByteSource, MULTIPLEFILES_REGULAR) {
Q.setFileInfo(files);
Q.buildQueueSynchronously();
ErrorCode code;
int fileNumber = 0;
ThreadCtx threadCtx(options, true);
while (true) {
auto byteSource = Q.getNextSource(&threadCtx, code);
if (!byteSource) {
break;
}
testReadSize(sizeToRead, *byteSource);
testReadPermission(randFiles[fileNumber].getPermission(), *byteSource);
++fileNumber;
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion test/wdt_e2e_simple_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ if [ -z "$WDT_TEST_SYMLINKS" ] ; then
fi
echo "WDT_TEST_SYMLINKS=$WDT_TEST_SYMLINKS"

# Set WDT_TEST_PERMISSION:
# to 1 : check if permissions match
# to 0 : when "find -printf %m" does not work, i.e. on Mac
if [ -z "$WDT_TEST_PERMISSION" ] ; then
WDT_TEST_PERMISSION=1
umask 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to set this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you are asking about why umask? Some machines (including mine) have a mask by default, which prevents giving write permission to Others. If we do not umask it, the file created on the receiver side will not have the write perm even if it is a 0777 on the writer side.

fi
echo "WDT_TEST_PERMISSION=$WDT_TEST_PERMISSION"

# Verbose / to debug failure:
#WDTBIN="_bin/wdt/wdt -minloglevel 0 -v 99"
# Normal:
Expand Down Expand Up @@ -96,6 +105,10 @@ do
-directory="$DIR/src" -filename="$base.$i" -gen_size_mb="$size"
done
done

if [ $WDT_TEST_PERMISSION -eq 1 ]; then
chmod 01777 $DIR/src/inp.0009765625.1
fi
echo "done with setup"

if [ $WDT_TEST_SYMLINKS -eq 1 ]; then
Expand Down Expand Up @@ -137,7 +150,7 @@ if [ $DO_VERIFY -eq 1 ] ; then
echo "Should be no diff"
(cd $DIR; diff -u src.md5s dst.md5s)
STATUS=$?
if [ $STATUS -eq 0 ] ; then
if [ $STATUS -eq 0 ] && [ $WDT_TEST_PERMISSION -eq 1 ]; then
(cd $DIR/src ; ( find . -type f -printf %f%m\\n | sort ) > ../src.perm )
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find . -type f -printf %f%m\\n doesn't work on Mac. Can you also test files with permissions other than 644?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently within the /tmp/wdtTest_[usrname], there are several files with 664, which include ".a" and ".b" if I remember correctly. Regarding Mac... I am not sure whether we need to consider that. @uddipta Could you clarify this? Similarly I think stat() might not work on Windows.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. we do support Mac. We run open source continuous builds here https://travis-ci.org/facebook/wdt
  2. In e2e simple test, I don't see any files having permissions other than 644.

So, we need to add a file with different permission for testing.

As Jason mentioned before, current find cmd does not work on mac. So, we can disable the test for now on Mac. You can do that using an environment variable. We can have an environment variable like SKIP_PERMISSION_TEST and set it in https://github.com/facebook/wdt/blob/master/build/travis_osx.sh.

If you have access to a mac, you can also try to make the test work for mac. Right now, find is failing for mac, but we are not checking the return code. Both, src.perm and dst.perm are empty, so the test is passing.

Also, run clangformat.sh once.

Every time you update this PR, you should see a travis build/test triggered.

Copy link
Contributor Author

@dliang36 dliang36 Apr 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. OK. I will add a environment var for that. Sorry but I do not have a mac at hand...

  2. Well... there are on my laptop...
    If I just change this line https://github.com/facebook/wdt/pull/155/files#diff-a77a3101b61bf7da9963a0791dba5bb6R247 to return 0644,
    The following tests FAILED:
    10 - FileReaderTests (Failed)
    12 - WdtBasicE2E (Failed)
    19 - WdtSimpleOdirectTest (Failed)
    For 12 & 19, we have things like this:
    Should be no diff
    --- src.perm 2017-04-05 14:56:37.893425997 -0700
    +++ dst.perm 2017-04-05 14:56:37.893425997 -0700
    @@ -1,7 +1,7 @@
    -a664
    -c664
    -file1664
    -file1664
    +a644
    +c644
    +file1644
    +file1644

(Part of "ls -l" output on the src dir is here.)
screenshot from 2017-04-05 15-05-34
Or...is this my OS specific again?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to chmod a file to have permission like 777. Just do that for file1.

Regarding adding test for mac, we will add it later.

(cd $DIR/dst ; ( find . -type f -printf %f%m\\n | sort ) > ../dst.perm )

Expand Down