From f988da6aa1d7ab170868ad04d7c6e21bbb178549 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 29 Oct 2024 17:07:13 -0500 Subject: [PATCH] refactor: remove unused TR_SYS_FILE_APPEND (#7206) --- libtransmission/file-posix.cc | 3 +-- libtransmission/file-win32.cc | 5 ----- libtransmission/file.h | 5 ++--- tests/libtransmission/file-test.cc | 13 +------------ 4 files changed, 4 insertions(+), 22 deletions(-) diff --git a/libtransmission/file-posix.cc b/libtransmission/file-posix.cc index 280c2537f..5919f1343 100644 --- a/libtransmission/file-posix.cc +++ b/libtransmission/file-posix.cc @@ -560,12 +560,11 @@ tr_sys_file_t tr_sys_file_open(char const* path, int flags, int permissions, tr_ int native_value; }; - auto constexpr NativeMap = std::array{ + auto constexpr NativeMap = std::array{ { { 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_WRITE, O_WRONLY }, { 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_SEQUENTIAL, TR_SYS_FILE_SEQUENTIAL, O_SEQUENTIAL } } }; diff --git a/libtransmission/file-win32.cc b/libtransmission/file-win32.cc index f96d11359..78af23270 100644 --- a/libtransmission/file-win32.cc +++ b/libtransmission/file-win32.cc @@ -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 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) { set_system_error(error, GetLastError()); diff --git a/libtransmission/file.h b/libtransmission/file.h index 12ccb3301..9db1ab6fc 100644 --- a/libtransmission/file.h +++ b/libtransmission/file.h @@ -50,9 +50,8 @@ enum tr_sys_file_open_flags_t TR_SYS_FILE_READ = (1 << 0), TR_SYS_FILE_WRITE = (1 << 1), TR_SYS_FILE_CREATE = (1 << 2), - TR_SYS_FILE_APPEND = (1 << 3), - TR_SYS_FILE_TRUNCATE = (1 << 4), - TR_SYS_FILE_SEQUENTIAL = (1 << 5) + TR_SYS_FILE_TRUNCATE = (1 << 3), + TR_SYS_FILE_SEQUENTIAL = (1 << 4) }; enum tr_sys_file_lock_flags_t diff --git a/tests/libtransmission/file-test.cc b/tests/libtransmission/file-test.cc index 3b12abf03..2f041cbbe 100644 --- a/tests/libtransmission/file-test.cc +++ b/tests/libtransmission/file-test.cc @@ -1128,22 +1128,11 @@ TEST_F(FileTest, fileOpen) tr_sys_path_remove(path1); 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); EXPECT_TRUE(info.has_value()); assert(info.has_value()); 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); EXPECT_NE(TR_BAD_SYS_FILE, fd); EXPECT_FALSE(error) << error;