google / google/codesearch

Second and newer indexing loses paths if one directory basename is a prefix

Đang mở
#55 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Go
Star
4k
Fork
403
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Easier to demonstrate.

``` make
% cat Makefile
.PHONY: all test clean

BAD1 = a
BAD2 = a-b

GOOD1 = a-x
GOOD2 = a-y

.PHONY: template good bad

template:
rm -rf test
mkdir -p test/$(VAR1) test/$(VAR2)
ls > test/$(VAR1)/a
ls > test/$(VAR2)/a
rm -f test/.csearchindex
/usr/bin/env CSEARCHINDEX=test/.csearchindex $(GOPATH)/bin/cindex test/$(VAR1) test/$(VAR2)
/usr/bin/env CSEARCHINDEX=test/.csearchindex $(GOPATH)/bin/cindex -list
# Just index them again to reproduce the bug
/usr/bin/env CSEARCHINDEX=test/.csearchindex $(GOPATH)/bin/cindex -verbose
/usr/bin/env CSEARCHINDEX=test/.csearchindex $(GOPATH)/bin/cindex -list
test `/usr/bin/env CSEARCHINDEX=test/.csearchindex $(GOPATH)/bin/cindex -list | wc -l` = 2

bad:
VAR1=$(BAD1) VAR2=$(BAD2) $(MAKE) template

good:
VAR1=$(GOOD1) VAR2=$(GOOD2) $(MAKE) template
```

No bug when test run with two directories where basenames are not a prefix or another:

``` sh
% make good
VAR1=a-x VAR2=a-y /Applications/Xcode.app/Contents/Developer/usr/bin/make template
rm -rf test
mkdir -p test/a-x test/a-y
ls > test/a-x/a
ls > test/a-y/a
rm -f test/.csearchindex
/usr/bin/env CSEARCHINDEX=test/.csearchindex /Users/xxxx/pkgs/go/bin/cindex test/a-x test/a-y
2016/02/08 17:37:14 index /Users/xxxx/work/codesearch/test/a-x
2016/02/08 17:37:14 index /Users/xxxx/work/codesearch/test/a-y
2016/02/08 17:37:14 flush index
2016/02/08 17:37:14 merge 0 files + mem
2016/02/08 17:37:14 166 data bytes, 1596 index bytes
2016/02/08 17:37:14 done
/usr/bin/env CSEARCHINDEX=test/.csearchindex /Users/xxxx/pkgs/go/bin/cindex -list
/Users/xxxx/work/codesearch/test/a-x
/Users/xxxx/work/codesearch/test/a-y
# Just index them again to reproduce the bug
/usr/bin/env CSEARCHINDEX=test/.csearchindex /Users/xxxx/pkgs/go/bin/cindex -verbose
2016/02/08 17:37:14 index /Users/xxxx/work/codesearch/test/a-x
2016/02/08 17:37:14 83 79 /Users/xxxx/work/codesearch/test/a-x/a
2016/02/08 17:37:14 index /Users/xxxx/work/codesearch/test/a-y
2016/02/08 17:37:14 83 79 /Users/xxxx/work/codesearch/test/a-y/a
2016/02/08 17:37:14 flush index
2016/02/08 17:37:14 merge 0 files + mem
2016/02/08 17:37:14 166 data bytes, 1596 index bytes
2016/02/08 17:37:14 merge test/.csearchindex test/.csearchindex~
2016/02/08 17:37:14 done
/usr/bin/env CSEARCHINDEX=test/.csearchindex /Users/xxxx/pkgs/go/bin/cindex -list
/Users/xxxx/work/codesearch/test/a-x
/Users/xxxx/work/codesearch/test/a-y
test `/usr/bin/env CSEARCHINDEX=test/.csearchindex /Users/xxxx/pkgs/go/bin/cindex -list | wc -l` = 2
```

Bug seen when test run with two directories where one basename is prefix of another:

``` sh
% make bad
VAR1=a VAR2=a-b /Applications/Xcode.app/Contents/Developer/usr/bin/make template
rm -rf test
mkdir -p test/a test/a-b
ls > test/a/a
ls > test/a-b/a
rm -f test/.csearchindex
/usr/bin/env CSEARCHINDEX=test/.csearchindex /Users/xxxx/pkgs/go/bin/cindex test/a test/a-b
2016/02/08 17:37:11 index /Users/xxxx/work/codesearch/test/a
2016/02/08 17:37:11 index /Users/xxxx/work/codesearch/test/a-b
2016/02/08 17:37:11 flush index
2016/02/08 17:37:11 merge 0 files + mem
2016/02/08 17:37:11 166 data bytes, 1592 index bytes
2016/02/08 17:37:11 done
/usr/bin/env CSEARCHINDEX=test/.csearchindex /Users/xxxx/pkgs/go/bin/cindex -list
/Users/xxxx/work/codesearch/test/a
/Users/xxxx/work/codesearch/test/a-b
# Just index them again to reproduce the bug
/usr/bin/env CSEARCHINDEX=test/.csearchindex /Users/xxxx/pkgs/go/bin/cindex -verbose
2016/02/08 17:37:11 index /Users/xxxx/work/codesearch/test/a
2016/02/08 17:37:11 83 79 /Users/xxxx/work/codesearch/test/a/a
2016/02/08 17:37:11 index /Users/xxxx/work/codesearch/test/a-b
2016/02/08 17:37:11 83 79 /Users/xxxx/work/codesearch/test/a-b/a
2016/02/08 17:37:11 flush index
2016/02/08 17:37:11 merge 0 files + mem
2016/02/08 17:37:11 166 data bytes, 1592 index bytes
2016/02/08 17:37:11 merge test/.csearchindex test/.csearchindex~
2016/02/08 17:37:11 done
/usr/bin/env CSEARCHINDEX=test/.csearchindex /Users/xxxx/pkgs/go/bin/cindex -list
/Users/xxxx/work/codesearch/test/a
test `/usr/bin/env CSEARCHINDEX=test/.csearchindex /Users/xxxx/pkgs/go/bin/cindex -list | wc -l` = 2
make[1]: *** [template] Error 1
make: *** [bad] Error 2
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Sử dụng bản tái hiện bằng Makefile để chạy các trường hợp đúng và sai, đặc biệt là việc lập chỉ mục cindex lặp lại với các thư mục có tên a và a-b. Đọc các entry point lập chỉ mục của cindex và index-merge liên quan đến -list và -verbose, sau đó xác minh rằng việc chạy lại index vẫn giữ nguyên cả hai đường dẫn và danh sách cuối cùng chứa hai thư mục.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
go
Lĩnh vực
search
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.