File::truncate() updates timestamps correctly. Also added test cases for this.
This commit is contained in:
parent
6448110975
commit
69f4c7976e
@ -46,6 +46,7 @@ void CryFile::truncate(off_t size) {
|
||||
device()->callFsActionCallbacks();
|
||||
auto blob = LoadBlob();
|
||||
blob->resize(size);
|
||||
parent()->updateModificationTimestampForChild(key());
|
||||
}
|
||||
|
||||
fspp::Dir::EntryType CryFile::getType() const {
|
||||
|
@ -116,6 +116,10 @@ unique_ref<FsBlobRef> CryNode::LoadBlob() const {
|
||||
return _device->LoadBlob(_key);
|
||||
}
|
||||
|
||||
const blockstore::Key &CryNode::key() const {
|
||||
return _key;
|
||||
}
|
||||
|
||||
void CryNode::stat(struct ::stat *result) const {
|
||||
device()->callFsActionCallbacks();
|
||||
if(_parent == none) {
|
||||
|
@ -27,6 +27,7 @@ protected:
|
||||
|
||||
CryDevice *device();
|
||||
const CryDevice *device() const;
|
||||
const blockstore::Key &key() const;
|
||||
cpputils::unique_ref<parallelaccessfsblobstore::FsBlobRef> LoadBlob() const;
|
||||
std::shared_ptr<const parallelaccessfsblobstore::DirBlobRef> parent() const;
|
||||
std::shared_ptr<parallelaccessfsblobstore::DirBlobRef> parent();
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "FsppOpenFileTest.h"
|
||||
#include "FsppDeviceTest_Timestamps.h"
|
||||
#include "FsppNodeTest_Timestamps.h"
|
||||
#include "FsppFileTest_Timestamps.h"
|
||||
#include "FsppOpenFileTest_Timestamps.h"
|
||||
|
||||
#define FSPP_ADD_FILESYTEM_TESTS(FS_NAME, FIXTURE) \
|
||||
@ -19,6 +20,7 @@
|
||||
INSTANTIATE_NODE_TEST_CASE( FS_NAME, FsppDeviceTest_Timestamps, FIXTURE); \
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppDirTest, FIXTURE); \
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppFileTest, FIXTURE); \
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppFileTest_Timestamps, FIXTURE); \
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppSymlinkTest, FIXTURE); \
|
||||
INSTANTIATE_NODE_TEST_CASE( FS_NAME, FsppNodeTest_Rename, FIXTURE); \
|
||||
INSTANTIATE_NODE_TEST_CASE( FS_NAME, FsppNodeTest_Stat, FIXTURE); \
|
||||
|
103
src/fspp/fstest/FsppFileTest_Timestamps.h
Normal file
103
src/fspp/fstest/FsppFileTest_Timestamps.h
Normal file
@ -0,0 +1,103 @@
|
||||
#pragma once
|
||||
#ifndef MESSMER_FSPP_FSTEST_FSPPFILETEST_TIMESTAMPS_H_
|
||||
#define MESSMER_FSPP_FSTEST_FSPPFILETEST_TIMESTAMPS_H_
|
||||
|
||||
#include "testutils/TimestampTestUtils.h"
|
||||
|
||||
template<class ConcreteFileSystemTestFixture>
|
||||
class FsppFileTest_Timestamps: public FileSystemTest<ConcreteFileSystemTestFixture>, public TimestampTestUtils<fspp::Node> {
|
||||
public:
|
||||
cpputils::unique_ref<fspp::File> CreateFileWithSize(const boost::filesystem::path &path, off_t size) {
|
||||
auto file = this->CreateFile(path);
|
||||
file->truncate(size);
|
||||
assert(stat(*file).st_size == size);
|
||||
return file;
|
||||
}
|
||||
};
|
||||
TYPED_TEST_CASE_P(FsppFileTest_Timestamps);
|
||||
|
||||
TYPED_TEST_P(FsppFileTest_Timestamps, open_nomode) {
|
||||
auto file = this->CreateFile("/myfile");
|
||||
auto operation = [&file] () {
|
||||
file->open(0);
|
||||
};
|
||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*file, operation, {this->ExpectDoesntUpdateAnyTimestamps});
|
||||
}
|
||||
|
||||
TYPED_TEST_P(FsppFileTest_Timestamps, open_rdonly) {
|
||||
auto file = this->CreateFile("/myfile");
|
||||
auto operation = [&file] () {
|
||||
file->open(O_RDONLY);
|
||||
};
|
||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*file, operation, {this->ExpectDoesntUpdateAnyTimestamps});
|
||||
}
|
||||
|
||||
TYPED_TEST_P(FsppFileTest_Timestamps, open_wronly) {
|
||||
auto file = this->CreateFile("/myfile");
|
||||
auto operation = [&file] () {
|
||||
file->open(O_WRONLY);
|
||||
};
|
||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*file, operation, {this->ExpectDoesntUpdateAnyTimestamps});
|
||||
}
|
||||
|
||||
TYPED_TEST_P(FsppFileTest_Timestamps, open_rdwr) {
|
||||
auto file = this->CreateFile("/myfile");
|
||||
auto operation = [&file] () {
|
||||
file->open(O_RDWR);
|
||||
};
|
||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*file, operation, {this->ExpectDoesntUpdateAnyTimestamps});
|
||||
}
|
||||
|
||||
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_empty_to_empty) {
|
||||
auto file = this->CreateFileWithSize("/myfile", 0);
|
||||
auto operation = [&file] () {
|
||||
file->truncate(0);
|
||||
};
|
||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*file, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||
}
|
||||
|
||||
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_empty_to_nonempty) {
|
||||
auto file = this->CreateFileWithSize("/myfile", 0);
|
||||
auto operation = [&file] () {
|
||||
file->truncate(10);
|
||||
};
|
||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*file, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||
}
|
||||
|
||||
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_nonempty_to_empty) {
|
||||
auto file = this->CreateFileWithSize("/myfile", 10);
|
||||
auto operation = [&file] () {
|
||||
file->truncate(0);
|
||||
};
|
||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*file, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||
}
|
||||
|
||||
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_nonempty_to_nonempty_shrink) {
|
||||
auto file = this->CreateFileWithSize("/myfile", 10);
|
||||
auto operation = [&file] () {
|
||||
file->truncate(5);
|
||||
};
|
||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*file, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||
}
|
||||
|
||||
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_nonempty_to_nonempty_grow) {
|
||||
auto file = this->CreateFileWithSize("/myfile", 10);
|
||||
auto operation = [&file] () {
|
||||
file->truncate(20);
|
||||
};
|
||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*file, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||
}
|
||||
|
||||
REGISTER_TYPED_TEST_CASE_P(FsppFileTest_Timestamps,
|
||||
open_nomode,
|
||||
open_rdonly,
|
||||
open_wronly,
|
||||
open_rdwr,
|
||||
truncate_empty_to_empty,
|
||||
truncate_empty_to_nonempty,
|
||||
truncate_nonempty_to_empty,
|
||||
truncate_nonempty_to_nonempty_shrink,
|
||||
truncate_nonempty_to_nonempty_grow
|
||||
);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user