Skip to content
1 change: 1 addition & 0 deletions scripts/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions scripts/filter_lint_by_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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)
11 changes: 9 additions & 2 deletions scripts/run_lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -62,7 +69,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" ]
Expand Down
56 changes: 35 additions & 21 deletions src/util/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Date: January 2012
#include <direct.h>
#include <Shlwapi.h>
#undef NOMINMAX
#include <util/unicode.h>
#define chdir _chdir
#define popen _popen
#define pclose _pclose
Expand Down Expand Up @@ -95,42 +96,55 @@ Function: delete_directory

\*******************************************************************/

void delete_directory(const std::string &path)
{
#ifdef _WIN32

std::string pattern=path+"\\*";

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)
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);
}

#endif

rmdir(path.c_str());
#endif
}

/*******************************************************************\
Expand Down