mirror of https://github.com/milvus-io/milvus.git
Fix GetDiskUsedSize not work (#20474)
Signed-off-by: xige-16 <xi.ge@zilliz.com> Signed-off-by: xige-16 <xi.ge@zilliz.com>pull/20749/head
parent
15badd0263
commit
34c88cea32
|
@ -202,6 +202,9 @@ LocalChunkManager::GetSizeOfDir(const std::string& dir) {
|
|||
if (boost::filesystem::is_regular_file(it->path())) {
|
||||
total_file_size += boost::filesystem::file_size(it->path());
|
||||
}
|
||||
if (boost::filesystem::is_directory(it->path())) {
|
||||
total_file_size += GetSizeOfDir(it->path().string());
|
||||
}
|
||||
}
|
||||
|
||||
return total_file_size;
|
||||
|
|
|
@ -229,3 +229,37 @@ TEST_F(LocalChunkManagerTest, ReadOffset) {
|
|||
exist = lcm.DirExist(path_prefix);
|
||||
EXPECT_EQ(exist, false);
|
||||
}
|
||||
|
||||
TEST_F(LocalChunkManagerTest, GetSizeOfDir) {
|
||||
auto& lcm = LocalChunkManager::GetInstance();
|
||||
auto path_prefix = lcm.GetPathPrefix();
|
||||
auto test_dir = path_prefix + "/" + "test_dir/";
|
||||
EXPECT_EQ(lcm.DirExist(test_dir), false);
|
||||
lcm.CreateDir(test_dir);
|
||||
EXPECT_EQ(lcm.DirExist(test_dir), true);
|
||||
EXPECT_EQ(lcm.GetSizeOfDir(test_dir), 0);
|
||||
|
||||
uint8_t data[] = {0x17, 0x32, 0x00, 0x34, 0x23, 0x23, 0x87, 0x98};
|
||||
// test get size of file in test_dir
|
||||
auto file1 = test_dir + "file";
|
||||
auto res = lcm.CreateFile(file1);
|
||||
EXPECT_EQ(res, true);
|
||||
lcm.Write(file1, data, sizeof(data));
|
||||
EXPECT_EQ(lcm.GetSizeOfDir(test_dir), sizeof(data));
|
||||
lcm.Remove(file1);
|
||||
auto exist = lcm.Exist(file1);
|
||||
EXPECT_EQ(exist, false);
|
||||
|
||||
// test get dir size with nested dirs
|
||||
auto nest_dir = test_dir + "nest_dir/";
|
||||
auto file2 = nest_dir + "file";
|
||||
res = lcm.CreateFile(file2);
|
||||
EXPECT_EQ(res, true);
|
||||
lcm.Write(file2, data, sizeof(data));
|
||||
EXPECT_EQ(lcm.GetSizeOfDir(test_dir), sizeof(data));
|
||||
lcm.RemoveDir(test_dir);
|
||||
|
||||
lcm.RemoveDir(path_prefix);
|
||||
exist = lcm.DirExist(path_prefix);
|
||||
EXPECT_EQ(exist, false);
|
||||
}
|
||||
|
|
|
@ -84,9 +84,9 @@ func GetCProtoBlob(cProto *C.CProto) []byte {
|
|||
|
||||
func GetLocalUsedSize() (int64, error) {
|
||||
var availableSize int64
|
||||
cSize := C.int64_t(availableSize)
|
||||
cSize := (*C.int64_t)(&availableSize)
|
||||
|
||||
status := C.GetLocalUsedSize(&cSize)
|
||||
status := C.GetLocalUsedSize(cSize)
|
||||
err := HandleCStatus(&status, "get local used size failed")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
|
|
@ -79,9 +79,9 @@ func HandleCStatus(status *C.CStatus, extraInfo string) error {
|
|||
|
||||
func GetLocalUsedSize() (int64, error) {
|
||||
var availableSize int64
|
||||
cSize := C.int64_t(availableSize)
|
||||
cSize := (*C.int64_t)(&availableSize)
|
||||
|
||||
status := C.GetLocalUsedSize(&cSize)
|
||||
status := C.GetLocalUsedSize(cSize)
|
||||
err := HandleCStatus(&status, "get local used size failed")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
|
Loading…
Reference in New Issue