forked from TrueCloudLab/rclone
test info: check file name lengths using 1,2,3,4 byte unicode characters
This commit is contained in:
parent
e57fe14b61
commit
a6ca4b3817
1 changed files with 34 additions and 10 deletions
|
@ -91,7 +91,7 @@ type results struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
stringNeedsEscaping map[string]internal.Position
|
stringNeedsEscaping map[string]internal.Position
|
||||||
controlResults map[string]internal.ControlResult
|
controlResults map[string]internal.ControlResult
|
||||||
maxFileLength int
|
maxFileLength [4]int
|
||||||
canWriteUnnormalized bool
|
canWriteUnnormalized bool
|
||||||
canReadUnnormalized bool
|
canReadUnnormalized bool
|
||||||
canReadRenormalized bool
|
canReadRenormalized bool
|
||||||
|
@ -125,7 +125,9 @@ func (r *results) Print() {
|
||||||
fmt.Printf("}\n")
|
fmt.Printf("}\n")
|
||||||
}
|
}
|
||||||
if checkLength {
|
if checkLength {
|
||||||
fmt.Printf("maxFileLength = %d\n", r.maxFileLength)
|
for i := range r.maxFileLength {
|
||||||
|
fmt.Printf("maxFileLength = %d // for %d byte unicode characters\n", r.maxFileLength[i], i+1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if checkNormalization {
|
if checkNormalization {
|
||||||
fmt.Printf("canWriteUnnormalized = %v\n", r.canWriteUnnormalized)
|
fmt.Printf("canWriteUnnormalized = %v\n", r.canWriteUnnormalized)
|
||||||
|
@ -150,7 +152,7 @@ func (r *results) WriteJSON() {
|
||||||
report.ControlCharacters = &r.controlResults
|
report.ControlCharacters = &r.controlResults
|
||||||
}
|
}
|
||||||
if checkLength {
|
if checkLength {
|
||||||
report.MaxFileLength = &r.maxFileLength
|
report.MaxFileLength = &r.maxFileLength[0]
|
||||||
}
|
}
|
||||||
if checkNormalization {
|
if checkNormalization {
|
||||||
report.CanWriteUnnormalized = &r.canWriteUnnormalized
|
report.CanWriteUnnormalized = &r.canWriteUnnormalized
|
||||||
|
@ -366,11 +368,27 @@ func (r *results) checkControlsList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the max file name size we can use
|
// find the max file name size we can use
|
||||||
func (r *results) findMaxLength() {
|
func (r *results) findMaxLength(characterLength int) {
|
||||||
|
var character rune
|
||||||
|
switch characterLength {
|
||||||
|
case 1:
|
||||||
|
character = 'a'
|
||||||
|
case 2:
|
||||||
|
character = 'á'
|
||||||
|
case 3:
|
||||||
|
character = '世'
|
||||||
|
case 4:
|
||||||
|
character = '🙂'
|
||||||
|
default:
|
||||||
|
panic("Bad characterLength")
|
||||||
|
}
|
||||||
|
if characterLength != len(string(character)) {
|
||||||
|
panic(fmt.Sprintf("Chose the wrong character length %q is %d not %d", character, len(string(character)), characterLength))
|
||||||
|
}
|
||||||
const maxLen = 16 * 1024
|
const maxLen = 16 * 1024
|
||||||
name := make([]byte, maxLen)
|
name := make([]rune, maxLen)
|
||||||
for i := range name {
|
for i := range name {
|
||||||
name[i] = 'a'
|
name[i] = character
|
||||||
}
|
}
|
||||||
// Find the first size of filename we can't write
|
// Find the first size of filename we can't write
|
||||||
i := sort.Search(len(name), func(i int) (fail bool) {
|
i := sort.Search(len(name), func(i int) (fail bool) {
|
||||||
|
@ -382,16 +400,20 @@ func (r *results) findMaxLength() {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
path := string(name[:i])
|
path := string(name[:i])
|
||||||
_, err := r.writeFile(path)
|
o, err := r.writeFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Infof(r.f, "Couldn't write file with name length %d: %v", i, err)
|
fs.Infof(r.f, "Couldn't write file with name length %d: %v", i, err)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
fs.Infof(r.f, "Wrote file with name length %d", i)
|
fs.Infof(r.f, "Wrote file with name length %d", i)
|
||||||
|
err = o.Remove(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
fs.Errorf(o, "Failed to remove test file")
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
r.maxFileLength = i - 1
|
r.maxFileLength[characterLength-1] = i - 1
|
||||||
fs.Infof(r.f, "Max file length is %d", r.maxFileLength)
|
fs.Infof(r.f, "Max file length is %d when writing %d byte characters %q", r.maxFileLength[characterLength-1], characterLength, character)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *results) checkStreaming() {
|
func (r *results) checkStreaming() {
|
||||||
|
@ -447,7 +469,9 @@ func readInfo(ctx context.Context, f fs.Fs) error {
|
||||||
r.checkControls()
|
r.checkControls()
|
||||||
}
|
}
|
||||||
if checkLength {
|
if checkLength {
|
||||||
r.findMaxLength()
|
for i := range r.maxFileLength {
|
||||||
|
r.findMaxLength(i + 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if checkNormalization {
|
if checkNormalization {
|
||||||
r.checkUTF8Normalization()
|
r.checkUTF8Normalization()
|
||||||
|
|
Loading…
Add table
Reference in a new issue