Skip to content

Commit

Permalink
iox-#1962 Remove unneeded function, more detailed error handling, fix…
Browse files Browse the repository at this point in the history
… typos, check invalidation of fd in move test

Signed-off-by: Christian Eltzschig <[email protected]>
  • Loading branch information
elfenpiff committed Apr 17, 2023
1 parent 55245f2 commit 8a17931
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Ownership

/// @brief Abstract implementation to manage things common to all file descriptor
/// based constructs like ownership and permissions.
/// @note Can be used by every class which provide the method 'get_file_handle'
/// @note Can be used by every class which provides the method 'get_file_handle'
/// via inheritance.
/// @code
/// class MyResourceBasedOnFileDescriptor: public FileManagementInterface<MyResourceBasedOnFileDescriptor> {
Expand Down
4 changes: 0 additions & 4 deletions iceoryx_hoofs/posix/filesystem/include/iox/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ class FileBuilder
public:
expected<File, FileCreationError> create(const FilePath& name) noexcept;
expected<File, FileCreationError> open(const FilePath& name) noexcept;

private:
expected<File, FileCreationError> open_impl(const bool print_error_on_non_existing_file,
const FilePath& name) noexcept;
};
} // namespace iox

Expand Down
11 changes: 7 additions & 4 deletions iceoryx_hoofs/posix/filesystem/source/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ expected<File, FileCreationError> FileBuilder::open(const FilePath& name) noexce
IOX_LOG(ERROR) << "Unable to create file since it already exists.";
return iox::error<FileCreationError>(FileCreationError::AlreadyExists);
default:
IOX_LOG(ERROR) << "Unable to open/create file due to insufficient permissions (" << result.get_error().errnum
IOX_LOG(ERROR) << "Unable to open/create file since an unknown error occurred (" << result.get_error().errnum
<< ").";
return iox::error<FileCreationError>(FileCreationError::UnknownError);
}
Expand Down Expand Up @@ -290,13 +290,13 @@ expected<FileOffsetError> File::set_offset(const uint64_t offset) const noexcept
case EINVAL:
IOX_FALLTHROUGH;
case ENXIO:
IOX_LOG(ERROR) << "Unable to set file offset position since it beyond the file limits.";
IOX_LOG(ERROR) << "Unable to set file offset position since it is beyond the file limits.";
return iox::error<FileOffsetError>(FileOffsetError::OffsetBeyondFileLimits);
case EOVERFLOW:
IOX_LOG(ERROR)
<< "Unable to set file offset position since the file is too large and the offset would overflow.";
return iox::error<FileOffsetError>(FileOffsetError::FileOffsetOverflow);
case EPIPE:
case ESPIPE:
IOX_LOG(ERROR) << "Unable to set file offset position since seeking is not supported by the file type.";
return iox::error<FileOffsetError>(FileOffsetError::SeekingNotSupportedByFileType);
default:
Expand Down Expand Up @@ -342,7 +342,7 @@ File::read_at(const uint64_t offset, uint8_t* const buffer, const uint64_t buffe
IOX_LOG(ERROR) << "Unable to read from file since an interrupt signal was received.";
return iox::error<FileReadError>(FileReadError::Interrupt);
case EINVAL:
IOX_LOG(ERROR) << "Unable to read from file since is unsuitable for reading.";
IOX_LOG(ERROR) << "Unable to read from file since it is unsuitable for reading.";
return iox::error<FileReadError>(FileReadError::FileUnsuitableForReading);
case EIO:
IOX_LOG(ERROR) << "Unable to read from file since an IO failure occurred.";
Expand Down Expand Up @@ -407,6 +407,9 @@ File::write_at(const uint64_t offset, const uint8_t* const buffer, const uint64_
case EPERM:
IOX_LOG(ERROR) << "Unable to write to file since the operation was prevented by a file seal.";
return iox::error<FileWriteError>(FileWriteError::PreventedByFileSeal);
case EIO:
IOX_LOG(ERROR) << "Unable to write to file since an IO failure occurred.";
return iox::error<FileWriteError>(FileWriteError::IoFailure);
default:
IOX_LOG(ERROR) << "Unable to write to file since an unknown error has occurred (" << result.get_error().errnum
<< ").";
Expand Down
2 changes: 2 additions & 0 deletions iceoryx_hoofs/test/moduletests/test_posix_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ TEST_F(File_test, MoveConstructedFileWorks)
EXPECT_THAT(*result, Eq(test_content.size()));

File sut2{std::move(sut.value())};
EXPECT_THAT(sut->get_file_handle(), -1);

std::array<uint8_t, 3> read_content{0};
auto read = sut2.read(read_content.data(), read_content.size());
Expand Down Expand Up @@ -475,6 +476,7 @@ TEST_F(File_test, MoveAssignedFileWorks)
ASSERT_FALSE(sut3.has_error());

sut2 = std::move(sut3.value());
EXPECT_THAT(sut3->get_file_handle(), -1);

std::array<uint8_t, 3> read_content{0};
auto read = sut2.read(read_content.data(), read_content.size());
Expand Down

0 comments on commit 8a17931

Please sign in to comment.