Skip to content

Commit

Permalink
Fix test error for ubuntu docker. replace 'mv' command to 'rename' (v…
Browse files Browse the repository at this point in the history
…esoft-inc#1387)

* Replace mv command process by `rename`.

* Warp by c++, and print the error.

* Suppose error if not return zero.
  • Loading branch information
Shylock-Hg authored and dangleptr committed Dec 9, 2019
1 parent 5da9299 commit fa0cdf1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/common/fs/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,14 @@ bool FileUtils::exist(const std::string& path) {
return access(path.c_str(), F_OK) == 0;
}

// static
bool FileUtils::rename(const std::string& src, const std::string& dst) {
auto status = ::rename(src.c_str(), dst.c_str());
LOG_IF(WARNING, status != 0) << "Rename " << src << " to " << dst << " failed, the errno: "
<< ::strerror(errno);
return status == 0;
}

std::vector<std::string> FileUtils::listAllTypedEntitiesInDir(
const char* dirpath,
FileType type,
Expand Down
4 changes: 4 additions & 0 deletions src/common/fs/FileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ class FileUtils final {
static bool makeDir(const std::string& dir, uint32_t mode = 0775);
// Check the path is exist
static bool exist(const std::string& path);
// Like the command `mv', apply to file and directory
// Refer to `man 3 rename'
// return false when rename failed
static bool rename(const std::string& src, const std::string& dst);

/**
* List all entities in the given directory, whose type matches
Expand Down
28 changes: 16 additions & 12 deletions src/kvstore/test/NebulaStoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <rocksdb/db.h>
#include <iostream>
#include "fs/TempDir.h"
#include "fs/FileUtils.h"
#include "kvstore/NebulaStore.h"
#include "kvstore/PartManager.h"
#include "kvstore/RocksEngine.h"
Expand Down Expand Up @@ -759,18 +760,21 @@ TEST(NebulaStoreTest, ThreeCopiesCheckpointTest) {
std::string rm = folly::stringPrintf("%s/disk%d/nebula/0", rootPath.path(), i);
fs::FileUtils::remove(folly::stringPrintf("%s/data", rm.data()).c_str(), true);
fs::FileUtils::remove(folly::stringPrintf("%s/wal", rm.data()).c_str(), true);
std::string mv = folly::stringPrintf(
"/usr/bin/mv %s/disk%d/nebula/0/checkpoints/snapshot/data %s/disk%d/nebula/0/data",
rootPath.path(), i , rootPath.path(), i);
sleep(1);
auto ret = system(mv.c_str());
ASSERT_EQ(0, ret);
mv = folly::stringPrintf(
"/usr/bin/mv %s/disk%d/nebula/0/checkpoints/snapshot/wal %s/disk%d/nebula/0/wal",
rootPath.path(), i , rootPath.path(), i);
sleep(1);
ret = system(mv.c_str());
ASSERT_EQ(0, ret);
std::string src = folly::stringPrintf(
"%s/disk%d/nebula/0/checkpoints/snapshot/data",
rootPath.path(), i);
std::string dst = folly::stringPrintf(
"%s/disk%d/nebula/0/data",
rootPath.path(), i);
ASSERT_TRUE(fs::FileUtils::rename(src, dst));

src = folly::stringPrintf(
"%s/disk%d/nebula/0/checkpoints/snapshot/wal",
rootPath.path(), i);
dst = folly::stringPrintf(
"%s/disk%d/nebula/0/wal",
rootPath.path(), i);
ASSERT_TRUE(fs::FileUtils::rename(src, dst));
}

LOG(INFO) << "Let's start the engine via checkpoint";
Expand Down

0 comments on commit fa0cdf1

Please sign in to comment.