salt icon indicating copy to clipboard operation
salt copied to clipboard

file.contains, file.contains_regex and file.contains_glob are broken for large files

Open djs52 opened this issue 13 years ago • 6 comments

All of these functions follow the pattern

  for each 32kb chunk of the file:
      search the chunk for the search string

If the search string straddles two chunks, it will not be found.

djs52 avatar Jan 03 '13 11:01 djs52

so I guess we need to incorporate an overlap here, thanks for the catch, we can get this in!

thatch45 avatar Jan 03 '13 16:01 thatch45

I thought we were overlapping, ie the initial load would contain more info than subsequent chunk loads.

Initial: 123

Feed it one more chunk: 234

etc...

Pedro Algarvio

----- Reply message ----- De: "Thomas S Hatch" [email protected] Para: "saltstack/salt" [email protected] Assunto: [salt] file.contains, file.contains_regex and file.contains_glob are broken for large files (#3127) Data: qui, Jan 3, 2013 16:40 so I guess we need to incorporate an overlap here, thanks for the catch, we can get this in!

—

Reply to this email directly or view it on GitHub.

s0undt3ch avatar Jan 03 '13 23:01 s0undt3ch

well, we can take a look, and leave some comments.

thatch45 avatar Jan 03 '13 23:01 thatch45

@s0undt3ch - rereading salt/utils/filebuffer.py, you are right, of course. It didn't jump out at me on first reading. Sorry for the noise!

djs52 avatar Jan 03 '13 23:01 djs52

I think the different use of "chunk" in salt/utils/filebuffer.py and salt/modules/file.py threw me. It might be helpful to explicitly document BufferedReader.next as returning a window into the file of up to size max_in_mem which advances by chunk_size on each iteration.

djs52 avatar Jan 03 '13 23:01 djs52

@djs52 I can always be wrong, but in this case, I'm glad I'm not, one less bug ;)

s0undt3ch avatar Jan 04 '13 00:01 s0undt3ch