From b63228c6759d09951c5303979bf3c7e97840a7c9 Mon Sep 17 00:00:00 2001 From: Nathan Phillips Date: Fri, 17 Mar 2017 10:59:21 +0000 Subject: [PATCH 1/8] delete_directory fails silently on subfolders --- src/util/file_util.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/util/file_util.cpp b/src/util/file_util.cpp index 5999d15ebfb..7cfea942a0c 100644 --- a/src/util/file_util.cpp +++ b/src/util/file_util.cpp @@ -107,7 +107,13 @@ void delete_directory(const std::string &path) struct dirent *ent; while((ent=readdir(dir))!=NULL) - remove((path+"/"+ent->d_name).c_str()); + { + std::string sub_path=path+"/"+ent->d_name; + if(ent->d_type==DT_DIR) + delete_directory(sub_path); + else + remove(sub_path.c_str()); + } closedir(dir); } From d110db0cb13de183c5860d5cad46d367d3272e15 Mon Sep 17 00:00:00 2001 From: Nathan Phillips Date: Tue, 21 Mar 2017 12:29:33 +0000 Subject: [PATCH 2/8] Version to work on Windows --- src/util/file_util.cpp | 50 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/util/file_util.cpp b/src/util/file_util.cpp index 7cfea942a0c..0a62549316e 100644 --- a/src/util/file_util.cpp +++ b/src/util/file_util.cpp @@ -26,6 +26,7 @@ Date: January 2012 #include #include #include +#include #define chdir _chdir #define popen _popen #define pclose _pclose @@ -79,33 +80,43 @@ Function: delete_directory \*******************************************************************/ -void delete_directory(const std::string &path) -{ - #ifdef _WIN32 - - std::string pattern=path+"\\*"; +#ifdef _WIN32 +void delete_directory_utf16(const std::wstring &path) +{ + std::wstring pattern=path + L"\\*"; // NOLINTNEXTLINE(readability/identifiers) - struct _finddata_t info; - - intptr_t handle=_findfirst(pattern.c_str(), &info); - - if(handle!=-1) + struct _wfinddata_t info; + intptr_t hFile=_wfindfirst(pattern.c_str(), &info); + if(hFile!=-1) { - unlink(info.name); - - while(_findnext(handle, &info)!=-1) - unlink(info.name); + do + { + if(wcscmp(info.name, L".")==0 || wcscmp(info.name, L"..")==0) + continue; + std::wstring sub_path=path+L"\\"+info.name; + if(info.attrib & _A_SUBDIR) + delete_directory_utf16(sub_path); + else + DeleteFileW(sub_path.c_str()); + } + while(_wfindnext(hFile, &info)==0); + _findclose(hFile); + RemoveDirectoryW(path.c_str()); } +} - #else +#endif +void delete_directory(const std::string &path) +{ +#ifdef _WIN32 + delete_directory_utf16(utf8_to_utf16_little_endian(path)); +#else DIR *dir=opendir(path.c_str()); - if(dir!=NULL) { struct dirent *ent; - while((ent=readdir(dir))!=NULL) { std::string sub_path=path+"/"+ent->d_name; @@ -114,13 +125,10 @@ void delete_directory(const std::string &path) else remove(sub_path.c_str()); } - closedir(dir); } - - #endif - rmdir(path.c_str()); +#endif } /*******************************************************************\ From 88816e9998eaf912d85c02eef887999aaa42a5b6 Mon Sep 17 00:00:00 2001 From: Nathan Phillips Date: Tue, 21 Mar 2017 14:03:39 +0000 Subject: [PATCH 3/8] Ignore stdout, only pass errors to filter script --- scripts/run_lint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run_lint.sh b/scripts/run_lint.sh index 9fc724fb92f..de6e2d49ccb 100755 --- a/scripts/run_lint.sh +++ b/scripts/run_lint.sh @@ -62,7 +62,7 @@ for file in $diff_files; do # Run the linting script and filter: # The errors from the linter go to STDERR so must be redirected to STDOUT - result=`$script_folder/cpplint.py $file 2>&1 | $script_folder/filter_lint_by_diff.py $diff_file $absolute_repository_root` + result=`$script_folder/cpplint.py $file 2>&1 >/dev/null | $script_folder/filter_lint_by_diff.py $diff_file $absolute_repository_root` # Providing some errors were relevant we print them out if [ "$result" ] From 9cd9843d3614898d1f9dee7baac318054fb288f1 Mon Sep 17 00:00:00 2001 From: Nathan Phillips Date: Thu, 16 Mar 2017 16:54:48 +0000 Subject: [PATCH 4/8] Comment in lint filter --- scripts/filter_lint_by_diff.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/scripts/filter_lint_by_diff.py b/scripts/filter_lint_by_diff.py index 7a4c506e27e..e018cce315c 100755 --- a/scripts/filter_lint_by_diff.py +++ b/scripts/filter_lint_by_diff.py @@ -8,11 +8,11 @@ print >>sys.stderr, "Usage: filter_lint_by_diff.py diff.patch repository_root_directory < cpplint_warnings.txt" sys.exit(1) -added_lines = set() repository_root = sys.argv[2] -diff = unidiff.PatchSet.from_filename(sys.argv[1]) -for diff_file in diff: +# Create a set of all the files and the specific lines within that file that are in the diff +added_lines = set() +for diff_file in unidiff.PatchSet.from_filename(sys.argv[1]): filename = diff_file.target_file # Skip files deleted in the tip (b side of the diff): if filename == "/dev/null": @@ -25,11 +25,12 @@ if diff_line.line_type == "+": added_lines.add((filename, diff_line.target_line_no)) -for l in sys.stdin: - bits = l.split(":") - if len(bits) < 3: +# Print the lines that are in the set +for line in sys.stdin: + line_parts = line.split(":") + if len(line_parts) < 3: continue - filename = os.path.join(repository_root, bits[0]) - linenum = int(bits[1]) + filename = os.path.join(repository_root, line_parts[0]) + linenum = int(line_parts[1]) if (filename, linenum) in added_lines: - sys.stdout.write(l) + sys.stdout.write(line) From 5fef8411b1d1948b020bddf19e64153c18580a8f Mon Sep 17 00:00:00 2001 From: Nathan Phillips Date: Thu, 16 Mar 2017 16:55:39 +0000 Subject: [PATCH 5/8] Work with submodules Made linter use paths relative to current submodule, not the lowest containing repository --- scripts/cpplint.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/cpplint.py b/scripts/cpplint.py index 52350b4923f..4346bd7a4ae 100755 --- a/scripts/cpplint.py +++ b/scripts/cpplint.py @@ -1145,6 +1145,7 @@ def RepositoryName(self): os.path.exists(os.path.join(current_dir, ".hg")) or os.path.exists(os.path.join(current_dir, ".svn"))): root_dir = current_dir + break; current_dir = os.path.dirname(current_dir) if (os.path.exists(os.path.join(root_dir, ".git")) or From 6bba4ab110b463c17fc1c92de3401b2800fe12ad Mon Sep 17 00:00:00 2001 From: Nathan Phillips Date: Tue, 21 Mar 2017 14:09:26 +0000 Subject: [PATCH 6/8] Work across repos Use the path of the containing repository of the current path, not the one the script is downloaded into --- scripts/run_lint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run_lint.sh b/scripts/run_lint.sh index de6e2d49ccb..f00b24c53e5 100755 --- a/scripts/run_lint.sh +++ b/scripts/run_lint.sh @@ -3,7 +3,7 @@ set -e script_folder=`dirname $0` -absolute_repository_root=`readlink -f $script_folder/..` +absolute_repository_root=`git rev-parse --show-toplevel` if [[ "$#" -gt 2 ]] then From 36dee831ad587bde498b1a8652e7083bcd0ee5dd Mon Sep 17 00:00:00 2001 From: Nathan Phillips Date: Tue, 21 Mar 2017 14:09:44 +0000 Subject: [PATCH 7/8] Check that filter_lint_by_diff.py exists --- scripts/run_lint.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/run_lint.sh b/scripts/run_lint.sh index f00b24c53e5..fa588f084a3 100755 --- a/scripts/run_lint.sh +++ b/scripts/run_lint.sh @@ -20,6 +20,13 @@ then exit 1 fi +if ! [[ -e $script_folder/filter_lint_by_diff.py ]] +then + echo "Lint filter script could not be found in the $script_folder directory" + echo "Ensure filter_lint_by_diff.py is inside the $script_folder directory then run again" + exit 1 +fi + if [[ "$#" -gt 0 ]] then git_start=$1 From 57fd36c3221e96dd82061d9f3325fd383d7a8027 Mon Sep 17 00:00:00 2001 From: Nathan Phillips Date: Wed, 22 Mar 2017 13:56:36 +0000 Subject: [PATCH 8/8] Prevent recursion into . and .. folders on Alpine Linux --- src/util/file_util.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/util/file_util.cpp b/src/util/file_util.cpp index 0a62549316e..50dc06473f4 100644 --- a/src/util/file_util.cpp +++ b/src/util/file_util.cpp @@ -30,6 +30,8 @@ Date: January 2012 #define chdir _chdir #define popen _popen #define pclose _pclose +#else +#include #endif #include "file_util.h" @@ -119,6 +121,9 @@ void delete_directory(const std::string &path) struct dirent *ent; while((ent=readdir(dir))!=NULL) { + // Needed for Alpine Linux + if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0) + continue; std::string sub_path=path+"/"+ent->d_name; if(ent->d_type==DT_DIR) delete_directory(sub_path);