-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added check for files bigger than 4GB #186
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing, however, some aspects of the patch can still be improved. Feel free to ask any questions on meeting the merge criteria.
src/woeusb
Outdated
@@ -272,6 +272,11 @@ init(){ | |||
exit 1 | |||
fi | |||
|
|||
if [ "${target_filesystem_type}" == 'FAT' ]; then | |||
check_for_big_files\ | |||
"${source_fs_mountpoint}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function arguments in line-continuation requires an additional indentation(TAB)
src/woeusb
Outdated
local source_fs_mountpoint="${1}" | ||
|
||
for i in $(find ${source_fs_mountpoint}/ -type f); do | ||
if (( $(du $i | cut -f -1) > 4194303 )); then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stat(1)
should be more suitable thandu(1)
to determine file size- Why
4194303
? Document the unit conversion in the above comments
src/woeusb
Outdated
check_for_big_files(){ | ||
local source_fs_mountpoint="${1}" | ||
|
||
for i in $(find ${source_fs_mountpoint}/ -type f); do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"${quote}"
"$(all)"
"${the}"
"$(expansions)"
(when possible)- The trailing slash after
source_fs_mountpoint
is unnecessary - The loop will fail when the source_fs contains filepaths with spaces, checkout delimiter - Reading null delimited strings through a Bash loop - Stack Overflow for a robust solution using process substitution and a specifically configured
read
loop. - For readability, avoid using
i
as a counter variable when there are semantically better options likefile
src/woeusb
Outdated
@@ -2004,6 +2009,19 @@ util_check_function_parameters_quantity(){ | |||
return 0 | |||
}; declare -fr util_check_function_parameters_quantity | |||
|
|||
##Check every file in source directory for files bigger than max fat32 file size (~4GB) | |||
check_for_big_files(){ | |||
local source_fs_mountpoint="${1}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I pedantically require variables to be set read-only if it is not expected to be modified later
src/woeusb
Outdated
@@ -2004,6 +2009,19 @@ util_check_function_parameters_quantity(){ | |||
return 0 | |||
}; declare -fr util_check_function_parameters_quantity | |||
|
|||
##Check every file in source directory for files bigger than max fat32 file size (~4GB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pad a single space after the #
symbol please
src/woeusb
Outdated
for i in $(find ${source_fs_mountpoint}/ -type f); do | ||
if (( $(du $i | cut -f -1) > 4194303 )); then | ||
echo_with_color red "Error: File $i is larger than that supported by the fat32 filesystem. Use NTFS (--target-filesystem NTFS)." | ||
exit 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return
a non-zero value instead of directly bailout from a function using exit
so that we can do more things in the caller function when we needed, for now, use the following snippet in the init
function:
if ! check_for_big_files\
"${source_fs_mountpoint}"; then
exit 1
fi
check_for_big_files returns status. Space after ##. file as counter variable. Comment explaining 4294967295. Read only variable source_fs_mountpoint.
src/woeusb
Outdated
echo_with_color red "Error: File $i is larger than that supported by the fat32 filesystem. Use NTFS (--target-filesystem NTFS)." | ||
exit 1 | ||
for file in $(find "${source_fs_mountpoint}" -type f); do | ||
if (( $(stat -c "%s" $file) > 4294967295 )); then # Max fat32 file size is 2^32 - 1 bytes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The process substitution will error when the path of file
contains spaces, quote it with double-quotes.
I checked it and it looks like it works
|
Oh you've set the |
Something like that?
|
@WaxyMocha |
LGFM, thanks! |
* Loop will break if filename contains newline(which is possible), use null-separated list instead. Refer-to: For loops over find output are fragile. Use find -exec or a while read loop. - SC2044 · koalaman/shellcheck Wiki <https://github.com/koalaman/shellcheck/wiki/SC2044> Signed-off-by: 林博仁(Buo-ren Lin) <[email protected]>
If source directory contain file with size grater than 4GB, script will end with message: