commit - c7edacbe8610722076a084e20304a6128280ef06
commit + c2939b27ec9c1ba93e59bd04d1001c1780cf25e7
blob - 3f4fbd8aecafd4938a205056f29188facaeb1e3c
blob + dd9e363064e1368f3b90a3e93c374093dd942de1
--- tests/test_open_file.cc
+++ tests/test_open_file.cc
{
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)};
{
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));
{
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));
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");
{
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));
{
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));
{
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));
{
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
},
error::Print{error_code}
);
- return (error_code == ENOENT) ? file_not_found : file_opening_error;
+ return (error_code == ENOENT) ? FILE_NOT_FOUND : FILE_OPENING_ERROR;
}
struct stat sb{};
if (fstat(opened_file.get(), &sb) == -1)
},
error::Print{}
);
- return file_opening_error;
+ return FILE_OPENING_ERROR;
}
if (S_ISDIR(sb.st_mode))
{
},
error::Print{error_code}
);
- return (error_code == ENOENT) ? file_not_found : file_opening_error;
+ return (error_code == ENOENT) ? FILE_NOT_FOUND : FILE_OPENING_ERROR;
}
}
- return file_opened;
+ return FILE_OPENED;
}
blob - 590540df0c18f30b106846d34ac69c0fe3cf54dc
blob + a16a4bda08cbdc43ea3f7d423708326518d3166d
--- vostok/open_file.h
+++ vostok/open_file.h
enum OpenFileResult
{
- file_opened,
+ FILE_OPENED,
- file_not_found,
- file_opening_error,
+ FILE_NOT_FOUND,
+ FILE_OPENING_ERROR,
};
-
OpenFileResult open_file(int directory_fd, NotNull<czstring> file_name, UniqueFd &opened_file);
blob - 95ed0e83b4699dcba4526fc6e971df47fb692a6c
blob + d4370280c07bcdf629918760944ebc867e2974ae
--- vostok/vostok.cc
+++ vostok/vostok.cc
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;
}