Conversation
39da4cb to
ebac878
Compare
ebac878 to
0d94749
Compare
| "testing" | ||
| ) | ||
|
|
||
| func FileMD5(path string) string { |
hw07_file_copying/copy.go
Outdated
| } | ||
|
|
||
| inFile, err := os.Open(fromPath) | ||
|
|
There was a problem hiding this comment.
в го обычно не делают пустую строку между вызовом, порождающем ошибку и проверкой этой ошибки
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.
лучше всё таки ошибку проверять каждый раз
require.NoError(t, err)
hw07_file_copying/copy.go
Outdated
|
|
||
| reader := bar.NewProxyReader(inFile) | ||
|
|
||
| io.CopyN(outFile, reader, limit) |
hw07_file_copying/copy.go
Outdated
| inFile, err := os.Open(fromPath) | ||
|
|
||
| if err != nil { | ||
| return err |
There was a problem hiding this comment.
всегда запаковывайте ошибки, полученные от других функций и бибилиотек, если в вашей функции несколько мест, где возвращается ошибка. Это позволит вам понимать где сломалось.
поправьте тут и всех других местах
пример
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.
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.
дефер этот надо делать сразу после успешного открытия файла
сейчас, если мы вышли в 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.
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.
seek возвращает ошибку - вы её тут потеряли.
| return fmt.Errorf("open output file: %w", err) | ||
| } | ||
|
|
||
| defer outFile.Close() |
There was a problem hiding this comment.
close тоже возвращает ошибку )
что с ней делвть конечно не ясно, но можно хотя бы залогать, чтобы потом не охотиться на ведьм
|
|
||
| var ( | ||
| ErrUnsupportedFile = errors.New("unsupported file") | ||
| // ErrUnsupportedFile = errors.New("unsupported file") |
There was a problem hiding this comment.
комменты в коде не хрвните, удаляйте
| bar := pb.StartNew(int(limit)) | ||
| bar.Start() | ||
|
|
||
| reader := bar.NewProxyReader(inFile) |
Домашнее задание №7 «Утилита для копирования файлов»
Чек-лист студента (Что это?)
go mod tidy..syncфайл. Зачем его удалять?test.sh).Критерии оценки
Зачёт от 7 баллов