From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- drivers/unix/dir_access_unix.cpp | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'drivers/unix/dir_access_unix.cpp') diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index 00103684c7..5d435d5176 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -50,12 +50,10 @@ #endif DirAccess *DirAccessUnix::create_fs() { - return memnew(DirAccessUnix); } Error DirAccessUnix::list_dir_begin() { - list_dir_end(); //close any previous dir opening! //char real_current_dir_name[2048]; //is this enough?! @@ -70,7 +68,6 @@ Error DirAccessUnix::list_dir_begin() { } bool DirAccessUnix::file_exists(String p_file) { - GLOBAL_LOCK_FUNCTION if (p_file.is_rel_path()) @@ -89,7 +86,6 @@ bool DirAccessUnix::file_exists(String p_file) { } bool DirAccessUnix::dir_exists(String p_dir) { - GLOBAL_LOCK_FUNCTION if (p_dir.is_rel_path()) @@ -104,7 +100,6 @@ bool DirAccessUnix::dir_exists(String p_dir) { } uint64_t DirAccessUnix::get_modified_time(String p_file) { - if (p_file.is_rel_path()) p_file = current_dir.plus_file(p_file); @@ -116,14 +111,12 @@ uint64_t DirAccessUnix::get_modified_time(String p_file) { if (success) { return flags.st_mtime; } else { - ERR_FAIL_V(0); }; return 0; }; String DirAccessUnix::get_next() { - if (!dir_stream) return ""; @@ -160,17 +153,14 @@ String DirAccessUnix::get_next() { } bool DirAccessUnix::current_is_dir() const { - return _cisdir; } bool DirAccessUnix::current_is_hidden() const { - return _cishidden; } void DirAccessUnix::list_dir_end() { - if (dir_stream) closedir(dir_stream); dir_stream = nullptr; @@ -198,7 +188,6 @@ static bool _filter_drive(struct mntent *mnt) { #endif static void _get_drives(List *list) { - #if defined(HAVE_MNTENT) && defined(X11_ENABLED) // Check /etc/mtab for the list of mounted partitions FILE *mtab = setmntent("/etc/mtab", "r"); @@ -252,7 +241,6 @@ static void _get_drives(List *list) { } int DirAccessUnix::get_drive_count() { - List list; _get_drives(&list); @@ -260,7 +248,6 @@ int DirAccessUnix::get_drive_count() { } String DirAccessUnix::get_drive(int p_drive) { - List list; _get_drives(&list); @@ -270,12 +257,10 @@ String DirAccessUnix::get_drive(int p_drive) { } bool DirAccessUnix::drives_are_shortcuts() { - return true; } Error DirAccessUnix::make_dir(String p_dir) { - GLOBAL_LOCK_FUNCTION if (p_dir.is_rel_path()) @@ -298,7 +283,6 @@ Error DirAccessUnix::make_dir(String p_dir) { } Error DirAccessUnix::change_dir(String p_dir) { - GLOBAL_LOCK_FUNCTION p_dir = fix_path(p_dir); @@ -343,10 +327,8 @@ Error DirAccessUnix::change_dir(String p_dir) { } String DirAccessUnix::get_current_dir(bool p_include_drive) { - String base = _get_root_path(); if (base != "") { - String bd = current_dir.replace_first(base, ""); if (bd.begins_with("/")) return _get_root_string() + bd.substr(1, bd.length()); @@ -357,7 +339,6 @@ String DirAccessUnix::get_current_dir(bool p_include_drive) { } Error DirAccessUnix::rename(String p_path, String p_new_path) { - if (p_path.is_rel_path()) p_path = get_current_dir().plus_file(p_path); @@ -372,7 +353,6 @@ Error DirAccessUnix::rename(String p_path, String p_new_path) { } Error DirAccessUnix::remove(String p_path) { - if (p_path.is_rel_path()) p_path = get_current_dir().plus_file(p_path); @@ -389,11 +369,9 @@ Error DirAccessUnix::remove(String p_path) { } size_t DirAccessUnix::get_space_left() { - #ifndef NO_STATVFS struct statvfs vfs; if (statvfs(current_dir.utf8().get_data(), &vfs) != 0) { - return 0; }; @@ -409,7 +387,6 @@ String DirAccessUnix::get_filesystem_type() const { } DirAccessUnix::DirAccessUnix() { - dir_stream = nullptr; _cisdir = false; @@ -425,7 +402,6 @@ DirAccessUnix::DirAccessUnix() { } DirAccessUnix::~DirAccessUnix() { - list_dir_end(); } -- cgit v1.2.3 From 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 16:41:43 +0200 Subject: Style: Enforce braces around if blocks and loops Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html --- drivers/unix/dir_access_unix.cpp | 49 ++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'drivers/unix/dir_access_unix.cpp') diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index 5d435d5176..325a88b573 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -61,8 +61,9 @@ Error DirAccessUnix::list_dir_begin() { //chdir(current_path.utf8().get_data()); dir_stream = opendir(current_dir.utf8().get_data()); //chdir(real_current_dir_name); - if (!dir_stream) + if (!dir_stream) { return ERR_CANT_OPEN; //error! + } return OK; } @@ -70,8 +71,9 @@ Error DirAccessUnix::list_dir_begin() { bool DirAccessUnix::file_exists(String p_file) { GLOBAL_LOCK_FUNCTION - if (p_file.is_rel_path()) + if (p_file.is_rel_path()) { p_file = current_dir.plus_file(p_file); + } p_file = fix_path(p_file); @@ -88,8 +90,9 @@ bool DirAccessUnix::file_exists(String p_file) { bool DirAccessUnix::dir_exists(String p_dir) { GLOBAL_LOCK_FUNCTION - if (p_dir.is_rel_path()) + if (p_dir.is_rel_path()) { p_dir = get_current_dir().plus_file(p_dir); + } p_dir = fix_path(p_dir); @@ -100,8 +103,9 @@ bool DirAccessUnix::dir_exists(String p_dir) { } uint64_t DirAccessUnix::get_modified_time(String p_file) { - if (p_file.is_rel_path()) + if (p_file.is_rel_path()) { p_file = current_dir.plus_file(p_file); + } p_file = fix_path(p_file); @@ -117,8 +121,9 @@ uint64_t DirAccessUnix::get_modified_time(String p_file) { }; String DirAccessUnix::get_next() { - if (!dir_stream) + if (!dir_stream) { return ""; + } dirent *entry = readdir(dir_stream); @@ -161,8 +166,9 @@ bool DirAccessUnix::current_is_hidden() const { } void DirAccessUnix::list_dir_end() { - if (dir_stream) + if (dir_stream) { closedir(dir_stream); + } dir_stream = nullptr; _cisdir = false; } @@ -263,8 +269,9 @@ bool DirAccessUnix::drives_are_shortcuts() { Error DirAccessUnix::make_dir(String p_dir) { GLOBAL_LOCK_FUNCTION - if (p_dir.is_rel_path()) + if (p_dir.is_rel_path()) { p_dir = get_current_dir().plus_file(p_dir); + } p_dir = fix_path(p_dir); @@ -291,8 +298,9 @@ Error DirAccessUnix::change_dir(String p_dir) { String prev_dir; char real_current_dir_name[2048]; ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == nullptr, ERR_BUG); - if (prev_dir.parse_utf8(real_current_dir_name)) + if (prev_dir.parse_utf8(real_current_dir_name)) { prev_dir = real_current_dir_name; //no utf8, maybe latin? + } // try_dir is the directory we are trying to change into String try_dir = ""; @@ -330,22 +338,25 @@ String DirAccessUnix::get_current_dir(bool p_include_drive) { String base = _get_root_path(); if (base != "") { String bd = current_dir.replace_first(base, ""); - if (bd.begins_with("/")) + if (bd.begins_with("/")) { return _get_root_string() + bd.substr(1, bd.length()); - else + } else { return _get_root_string() + bd; + } } return current_dir; } Error DirAccessUnix::rename(String p_path, String p_new_path) { - if (p_path.is_rel_path()) + if (p_path.is_rel_path()) { p_path = get_current_dir().plus_file(p_path); + } p_path = fix_path(p_path); - if (p_new_path.is_rel_path()) + if (p_new_path.is_rel_path()) { p_new_path = get_current_dir().plus_file(p_new_path); + } p_new_path = fix_path(p_new_path); @@ -353,19 +364,22 @@ Error DirAccessUnix::rename(String p_path, String p_new_path) { } Error DirAccessUnix::remove(String p_path) { - if (p_path.is_rel_path()) + if (p_path.is_rel_path()) { p_path = get_current_dir().plus_file(p_path); + } p_path = fix_path(p_path); struct stat flags; - if ((stat(p_path.utf8().get_data(), &flags) != 0)) + if ((stat(p_path.utf8().get_data(), &flags) != 0)) { return FAILED; + } - if (S_ISDIR(flags.st_mode)) + if (S_ISDIR(flags.st_mode)) { return ::rmdir(p_path.utf8().get_data()) == 0 ? OK : FAILED; - else + } else { return ::unlink(p_path.utf8().get_data()) == 0 ? OK : FAILED; + } } size_t DirAccessUnix::get_space_left() { @@ -395,8 +409,9 @@ DirAccessUnix::DirAccessUnix() { // set current directory to an absolute path of the current directory char real_current_dir_name[2048]; ERR_FAIL_COND(getcwd(real_current_dir_name, 2048) == nullptr); - if (current_dir.parse_utf8(real_current_dir_name)) + if (current_dir.parse_utf8(real_current_dir_name)) { current_dir = real_current_dir_name; + } change_dir(current_dir); } -- cgit v1.2.3