commit c2939b27ec9c1ba93e59bd04d1001c1780cf25e7 from: Aleksey Ryndin date: Wed Aug 30 12:13:34 2023 UTC Refectoring: C++ code style commit - c7edacbe8610722076a084e20304a6128280ef06 commit + c2939b27ec9c1ba93e59bd04d1001c1780cf25e7 blob - 3f4fbd8aecafd4938a205056f29188facaeb1e3c blob + dd9e363064e1368f3b90a3e93c374093dd942de1 --- tests/test_open_file.cc +++ tests/test_open_file.cc @@ -29,9 +29,9 @@ TEST_START(test_open_file) { UniqueFd opened_file; - IS_TRUE(open_file(dir.get(), "", opened_file) == file_not_found and !opened_file); - IS_TRUE(open_file(dir.get(), "non-existent-file", opened_file) == file_not_found and !opened_file); - IS_TRUE(open_file(dir.get(), "non-existent-dir/file", opened_file) == file_not_found and !opened_file); + IS_TRUE(open_file(dir.get(), "", opened_file) == FILE_NOT_FOUND and !opened_file); + IS_TRUE(open_file(dir.get(), "non-existent-file", opened_file) == FILE_NOT_FOUND and !opened_file); + IS_TRUE(open_file(dir.get(), "non-existent-dir/file", opened_file) == FILE_NOT_FOUND and !opened_file); } const UniqueFd index_gmi{openat(dir.get(), "index.gmi", O_RDONLY | O_CREAT | O_EXCL, S_IRWXU)}; @@ -41,7 +41,7 @@ TEST_START(test_open_file) { UniqueFd opened_file; - IS_TRUE(open_file(dir.get(), "", opened_file) == file_opened and opened_file); + IS_TRUE(open_file(dir.get(), "", opened_file) == FILE_OPENED and opened_file); struct stat sb2{}; IS_TRUE_ERRNO(fstat(opened_file.get(), &sb2) != -1, "Stat file " << ss.str().c_str() << "/index.gmi"); IS_TRUE((sb1.st_dev == sb2.st_dev) && (sb1.st_ino == sb2.st_ino)); @@ -49,7 +49,7 @@ TEST_START(test_open_file) { UniqueFd opened_file; - IS_TRUE(open_file(dir.get(), "index.gmi", opened_file) == file_opened and opened_file); + IS_TRUE(open_file(dir.get(), "index.gmi", opened_file) == FILE_OPENED and opened_file); struct stat sb2{}; IS_TRUE_ERRNO(fstat(opened_file.get(), &sb2) != -1, "Stat file " << ss.str().c_str() << "/index.gmi"); IS_TRUE((sb1.st_dev == sb2.st_dev) && (sb1.st_ino == sb2.st_ino)); @@ -58,8 +58,8 @@ TEST_START(test_open_file) IS_TRUE_ERRNO(mkdirat(dir.get(), "subdir", S_IRWXU) != -1, "Create directory " << ss.str().c_str() << "/subdir"); { UniqueFd opened_file; - IS_TRUE(open_file(dir.get(), "subdir", opened_file) == file_not_found and !opened_file); - IS_TRUE(open_file(dir.get(), "subdir/", opened_file) == file_not_found and !opened_file); + IS_TRUE(open_file(dir.get(), "subdir", opened_file) == FILE_NOT_FOUND and !opened_file); + IS_TRUE(open_file(dir.get(), "subdir/", opened_file) == FILE_NOT_FOUND and !opened_file); } const UniqueFd subdir{openat(dir.get(), "subdir", O_RDONLY | O_DIRECTORY)}; IS_TRUE_ERRNO(subdir, "Open directory " << ss.str().c_str() << "/subdir"); @@ -70,7 +70,7 @@ TEST_START(test_open_file) { UniqueFd opened_file; - IS_TRUE(open_file(dir.get(), "subdir", opened_file) == file_opened and opened_file); + IS_TRUE(open_file(dir.get(), "subdir", opened_file) == FILE_OPENED and opened_file); struct stat sb2{}; IS_TRUE_ERRNO(fstat(opened_file.get(), &sb2) != -1, "Stat file " << ss.str().c_str() << "/subdir/index.gmi"); IS_TRUE((sb1.st_dev == sb2.st_dev) && (sb1.st_ino == sb2.st_ino)); @@ -78,7 +78,7 @@ TEST_START(test_open_file) { UniqueFd opened_file; - IS_TRUE(open_file(dir.get(), "subdir/", opened_file) == file_opened and opened_file); + IS_TRUE(open_file(dir.get(), "subdir/", opened_file) == FILE_OPENED and opened_file); struct stat sb2{}; IS_TRUE_ERRNO(fstat(opened_file.get(), &sb2) != -1, "Stat file " << ss.str().c_str() << "/subdir/index.gmi"); IS_TRUE((sb1.st_dev == sb2.st_dev) && (sb1.st_ino == sb2.st_ino)); @@ -86,7 +86,7 @@ TEST_START(test_open_file) { UniqueFd opened_file; - IS_TRUE(open_file(dir.get(), "subdir/index.gmi", opened_file) == file_opened and opened_file); + IS_TRUE(open_file(dir.get(), "subdir/index.gmi", opened_file) == FILE_OPENED and opened_file); struct stat sb2{}; IS_TRUE_ERRNO(fstat(opened_file.get(), &sb2) != -1, "Stat file " << ss.str().c_str() << "/subdir/index.gmi"); IS_TRUE((sb1.st_dev == sb2.st_dev) && (sb1.st_ino == sb2.st_ino)); @@ -97,7 +97,7 @@ TEST_START(test_open_file) { UniqueFd opened_file; - IS_TRUE(open_file(dir.get(), "subdir/EPERM.gmi", opened_file) == file_opening_error and !opened_file); + IS_TRUE(open_file(dir.get(), "subdir/EPERM.gmi", opened_file) == FILE_OPENING_ERROR and !opened_file); } IS_TRUE_ERRNO(unlinkat(subdir.get(), "EPERM.gmi", 0) != -1, "Remove file " << ss.str().c_str() << "/subdir/EPERM.gmi"); blob - 57e66102e99feb3ea744c75c80fe401f4e460b6d blob + 1fa3fbf6f7544b1b63f6fdfb18cabea02fe971c2 --- vostok/open_file.cc +++ vostok/open_file.cc @@ -31,7 +31,7 @@ OpenFileResult open_file(int directory_fd, NotNull file_name, UniqueFd &opened_file); blob - 95ed0e83b4699dcba4526fc6e971df47fb692a6c blob + d4370280c07bcdf629918760944ebc867e2974ae --- vostok/vostok.cc +++ vostok/vostok.cc @@ -97,14 +97,14 @@ void client_thread(const transport::AcceptedClient *ac const auto open_file_result = open_file(directory_fd, request.get_path().data(), opened_file); switch (open_file_result) { - case file_not_found: + case FILE_NOT_FOUND: send_response(accepted_client->get_ctx(), gemini::STATUS_51_NOT_FOUND, meta::not_found); return; - case file_opening_error: + case FILE_OPENING_ERROR: send_response(accepted_client->get_ctx(), gemini::STATUS_40_TEMPORARY_FAILURE, meta::temporary_failure); return; - case file_opened: + case FILE_OPENED: assert(opened_file); break; }