2017-03-02 19:16:18 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <folly/Format.h>
|
|
|
|
#include <folly/String.h>
|
2017-11-15 23:48:58 +03:00
|
|
|
#include <folly/test/TestUtils.h>
|
2017-03-02 19:16:18 +03:00
|
|
|
#include <gtest/gtest.h>
|
2017-11-15 23:48:58 +03:00
|
|
|
|
2017-03-02 19:16:18 +03:00
|
|
|
#include "eden/fs/inodes/EdenMount.h"
|
|
|
|
#include "eden/fs/inodes/FileInode.h"
|
2017-11-15 23:48:58 +03:00
|
|
|
#include "eden/fs/inodes/InodeMap.h"
|
2017-03-02 19:16:18 +03:00
|
|
|
#include "eden/fs/inodes/TreeInode.h"
|
|
|
|
#include "eden/fs/testharness/FakeBackingStore.h"
|
2017-03-03 01:20:32 +03:00
|
|
|
#include "eden/fs/testharness/FakeTreeBuilder.h"
|
2017-03-02 19:16:18 +03:00
|
|
|
#include "eden/fs/testharness/TestMount.h"
|
|
|
|
#include "eden/fs/testharness/TestUtil.h"
|
2017-04-14 21:31:48 +03:00
|
|
|
#include "eden/fs/utils/Bug.h"
|
2017-03-02 19:16:18 +03:00
|
|
|
|
|
|
|
using namespace facebook::eden;
|
|
|
|
using folly::StringPiece;
|
|
|
|
|
|
|
|
class SymlinkTest : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
void SetUp() override {
|
|
|
|
// Set up a directory structure that we will use for most
|
|
|
|
// of the tests below
|
2017-03-03 01:20:32 +03:00
|
|
|
FakeTreeBuilder builder;
|
|
|
|
builder.setFiles({
|
2017-03-02 19:16:18 +03:00
|
|
|
{"doc.txt", "hello\n"},
|
|
|
|
});
|
2017-03-03 01:20:32 +03:00
|
|
|
mount_.initialize(builder);
|
|
|
|
mount_.mkdir("a");
|
2017-03-02 19:16:18 +03:00
|
|
|
}
|
|
|
|
|
2017-03-03 01:20:32 +03:00
|
|
|
TestMount mount_;
|
2017-03-02 19:16:18 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(SymlinkTest, makeSymlink) {
|
|
|
|
StringPiece name{"s1"}; // node to create in the filesystem
|
|
|
|
StringPiece target{"foo!"}; // the value we want readlink to return
|
|
|
|
|
2017-03-03 01:20:32 +03:00
|
|
|
auto root = mount_.getTreeInode(RelativePathPiece());
|
2017-03-02 19:16:18 +03:00
|
|
|
auto inode = root->symlink(PathComponentPiece{name}, target);
|
2017-12-15 03:36:38 +03:00
|
|
|
EXPECT_EQ(dtype_t::Symlink, inode->getType());
|
2017-03-02 19:16:18 +03:00
|
|
|
EXPECT_EQ(inode->readlink().get(), target);
|
|
|
|
// Let's make sure that we can load it up and see the right results
|
2017-03-03 01:20:32 +03:00
|
|
|
auto loadedInode = mount_.getFileInode(RelativePathPiece{name});
|
2017-03-02 19:16:18 +03:00
|
|
|
EXPECT_EQ(loadedInode->readlink().get(), target);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymlinkTest, makeSymlinkCollisionFile) {
|
|
|
|
StringPiece name{"doc.txt"}; // node to create in the filesystem
|
|
|
|
StringPiece target{"foo!"}; // the value we want readlink to return
|
|
|
|
|
2017-03-03 01:20:32 +03:00
|
|
|
auto root = mount_.getTreeInode(RelativePathPiece());
|
2017-03-02 19:16:18 +03:00
|
|
|
// Name already exists, so we expect this to fail
|
|
|
|
EXPECT_THROW_ERRNO(root->symlink(PathComponentPiece{name}, target), EEXIST);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymlinkTest, makeSymlinkCollisionDir) {
|
|
|
|
StringPiece name{"a"}; // node to create in the filesystem
|
|
|
|
StringPiece target{"foo!"}; // the value we want readlink to return
|
|
|
|
|
2017-03-03 01:20:32 +03:00
|
|
|
auto root = mount_.getTreeInode(RelativePathPiece());
|
2017-03-02 19:16:18 +03:00
|
|
|
// Name already exists, so we expect this to fail
|
|
|
|
EXPECT_THROW_ERRNO(root->symlink(PathComponentPiece{name}, target), EEXIST);
|
|
|
|
}
|