1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-22 07:42:37 +00:00

refactor: remove unused TR_SYS_FILE_APPEND (#7206)

This commit is contained in:
Charles Kerr 2024-10-29 17:07:13 -05:00 committed by GitHub
parent c1047b8009
commit f988da6aa1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 4 additions and 22 deletions

View file

@ -560,12 +560,11 @@ tr_sys_file_t tr_sys_file_open(char const* path, int flags, int permissions, tr_
int native_value; int native_value;
}; };
auto constexpr NativeMap = std::array<native_map_item, 8>{ auto constexpr NativeMap = std::array<native_map_item, 7U>{
{ { TR_SYS_FILE_READ | TR_SYS_FILE_WRITE, TR_SYS_FILE_READ | TR_SYS_FILE_WRITE, O_RDWR }, { { TR_SYS_FILE_READ | TR_SYS_FILE_WRITE, TR_SYS_FILE_READ | TR_SYS_FILE_WRITE, O_RDWR },
{ TR_SYS_FILE_READ | TR_SYS_FILE_WRITE, TR_SYS_FILE_READ, O_RDONLY }, { TR_SYS_FILE_READ | TR_SYS_FILE_WRITE, TR_SYS_FILE_READ, O_RDONLY },
{ TR_SYS_FILE_READ | TR_SYS_FILE_WRITE, TR_SYS_FILE_WRITE, O_WRONLY }, { TR_SYS_FILE_READ | TR_SYS_FILE_WRITE, TR_SYS_FILE_WRITE, O_WRONLY },
{ TR_SYS_FILE_CREATE, TR_SYS_FILE_CREATE, O_CREAT }, { TR_SYS_FILE_CREATE, TR_SYS_FILE_CREATE, O_CREAT },
{ TR_SYS_FILE_APPEND, TR_SYS_FILE_APPEND, O_APPEND },
{ TR_SYS_FILE_TRUNCATE, TR_SYS_FILE_TRUNCATE, O_TRUNC }, { TR_SYS_FILE_TRUNCATE, TR_SYS_FILE_TRUNCATE, O_TRUNC },
{ TR_SYS_FILE_SEQUENTIAL, TR_SYS_FILE_SEQUENTIAL, O_SEQUENTIAL } } { TR_SYS_FILE_SEQUENTIAL, TR_SYS_FILE_SEQUENTIAL, O_SEQUENTIAL } }
}; };

View file

@ -825,11 +825,6 @@ tr_sys_file_t tr_sys_file_open(char const* path, int flags, int /*permissions*/,
auto ret = open_file(path, native_access, native_disposition, native_flags, error); auto ret = open_file(path, native_access, native_disposition, native_flags, error);
auto success = ret != TR_BAD_SYS_FILE; auto success = ret != TR_BAD_SYS_FILE;
if (success && (flags & TR_SYS_FILE_APPEND) != 0)
{
success = SetFilePointer(ret, 0, nullptr, FILE_END) != INVALID_SET_FILE_POINTER;
}
if (!success) if (!success)
{ {
set_system_error(error, GetLastError()); set_system_error(error, GetLastError());

View file

@ -50,9 +50,8 @@ enum tr_sys_file_open_flags_t
TR_SYS_FILE_READ = (1 << 0), TR_SYS_FILE_READ = (1 << 0),
TR_SYS_FILE_WRITE = (1 << 1), TR_SYS_FILE_WRITE = (1 << 1),
TR_SYS_FILE_CREATE = (1 << 2), TR_SYS_FILE_CREATE = (1 << 2),
TR_SYS_FILE_APPEND = (1 << 3), TR_SYS_FILE_TRUNCATE = (1 << 3),
TR_SYS_FILE_TRUNCATE = (1 << 4), TR_SYS_FILE_SEQUENTIAL = (1 << 4)
TR_SYS_FILE_SEQUENTIAL = (1 << 5)
}; };
enum tr_sys_file_lock_flags_t enum tr_sys_file_lock_flags_t

View file

@ -1128,22 +1128,11 @@ TEST_F(FileTest, fileOpen)
tr_sys_path_remove(path1); tr_sys_path_remove(path1);
createFileWithContents(path1, "test"); createFileWithContents(path1, "test");
/* Pointer is at the end of file */ /* File gets truncated */
auto info = tr_sys_path_get_info(path1, TR_SYS_PATH_NO_FOLLOW); auto info = tr_sys_path_get_info(path1, TR_SYS_PATH_NO_FOLLOW);
EXPECT_TRUE(info.has_value()); EXPECT_TRUE(info.has_value());
assert(info.has_value()); assert(info.has_value());
EXPECT_EQ(4U, info->size); EXPECT_EQ(4U, info->size);
fd = tr_sys_file_open(path1, TR_SYS_FILE_WRITE | TR_SYS_FILE_APPEND, 0600, &error);
EXPECT_NE(TR_BAD_SYS_FILE, fd);
EXPECT_FALSE(error) << error;
tr_sys_file_write(fd, "s", 1, nullptr); /* On *NIX, pointer is positioned on each write but not initially */
tr_sys_file_close(fd);
/* File gets truncated */
info = tr_sys_path_get_info(path1, TR_SYS_PATH_NO_FOLLOW);
EXPECT_TRUE(info.has_value());
assert(info.has_value());
EXPECT_EQ(5U, info->size);
fd = tr_sys_file_open(path1, TR_SYS_FILE_WRITE | TR_SYS_FILE_TRUNCATE, 0600, &error); fd = tr_sys_file_open(path1, TR_SYS_FILE_WRITE | TR_SYS_FILE_TRUNCATE, 0600, &error);
EXPECT_NE(TR_BAD_SYS_FILE, fd); EXPECT_NE(TR_BAD_SYS_FILE, fd);
EXPECT_FALSE(error) << error; EXPECT_FALSE(error) << error;