-
Notifications
You must be signed in to change notification settings - Fork 0
HW7 is completed #7
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
base: master
Are you sure you want to change the base?
Conversation
39da4cb to
ebac878
Compare
ebac878 to
0d94749
Compare
| "testing" | ||
| ) | ||
|
|
||
| func FileMD5(path string) string { |
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.
хорошая мысль
hw07_file_copying/copy.go
Outdated
| } | ||
|
|
||
| inFile, err := os.Open(fromPath) | ||
|
|
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.
в го обычно не делают пустую строку между вызовом, порождающем ошибку и проверкой этой ошибки
hw07_file_copying/copy_test.go
Outdated
| err = Copy("testdata/input.txt", "/tmp/offset_is_bigger_then_file_size.txt", 100000, 0) | ||
| require.Error(t, err) | ||
|
|
||
| Copy("testdata/input.txt", "/tmp/copy_offset0_limit0.txt", 0, 0) |
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.
лучше всё таки ошибку проверять каждый раз
require.NoError(t, err)
hw07_file_copying/copy.go
Outdated
|
|
||
| reader := bar.NewProxyReader(inFile) | ||
|
|
||
| io.CopyN(outFile, reader, limit) |
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.
нет проверки ошибки
hw07_file_copying/copy.go
Outdated
| inFile, err := os.Open(fromPath) | ||
|
|
||
| if err != nil { | ||
| return err |
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 fmt.Errorf("open input file: %w", err)
hw07_file_copying/copy.go
Outdated
|
|
||
| fileStat, err := os.Stat(fromPath) | ||
| if err != nil { | ||
| return err |
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 fmt.Errorf("read input file info: %w", err)
hw07_file_copying/copy.go
Outdated
| return ErrOffsetExceedsFileSize | ||
| } | ||
|
|
||
| defer inFile.Close() |
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.
дефер этот надо делать сразу после успешного открытия файла
сейчас, если мы вышли в 34 или 29 строек - файл останется открытым
hw07_file_copying/copy.go
Outdated
| outFile, err := os.Create(toPath) | ||
|
|
||
| if err != nil { | ||
| return err |
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 fmt.Errorf("open output file: %w", err)
caae1c4 to
255cfff
Compare
| defer outFile.Close() | ||
|
|
||
| if offset > 0 { | ||
| inFile.Seek(offset, io.SeekStart) |
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.
seek возвращает ошибку - вы её тут потеряли.
| return fmt.Errorf("open output file: %w", err) | ||
| } | ||
|
|
||
| defer outFile.Close() |
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.
close тоже возвращает ошибку )
что с ней делвть конечно не ясно, но можно хотя бы залогать, чтобы потом не охотиться на ведьм
|
|
||
| var ( | ||
| ErrUnsupportedFile = errors.New("unsupported file") | ||
| // ErrUnsupportedFile = errors.New("unsupported file") |
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.
комменты в коде не хрвните, удаляйте
| bar := pb.StartNew(int(limit)) | ||
| bar.Start() | ||
|
|
||
| reader := bar.NewProxyReader(inFile) |
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.
нейминг слабый
Домашнее задание №7 «Утилита для копирования файлов»
Чек-лист студента (Что это?)
go mod tidy..syncфайл. Зачем его удалять?test.sh).Критерии оценки
Зачёт от 7 баллов