Skip to content

Conversation

@sofiiakulish
Copy link
Owner

@sofiiakulish sofiiakulish commented Sep 3, 2022

Домашнее задание №7 «Утилита для копирования файлов»

Чек-лист студента (Что это?)

Критерии оценки

  • Пайплайн зелёный - 4 балла
  • Добавлены юнит-тесты - до 4 баллов
  • Понятность и чистота кода - до 2 баллов

Зачёт от 7 баллов

"testing"
)

func FileMD5(path string) string {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

хорошая мысль

}

inFile, err := os.Open(fromPath)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в го обычно не делают пустую строку между вызовом, порождающем ошибку и проверкой этой ошибки

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше всё таки ошибку проверять каждый раз
require.NoError(t, err)


reader := bar.NewProxyReader(inFile)

io.CopyN(outFile, reader, limit)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нет проверки ошибки

inFile, err := os.Open(fromPath)

if err != nil {
return err

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)


fileStat, err := os.Stat(fromPath)
if err != nil {
return err

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)

return ErrOffsetExceedsFileSize
}

defer inFile.Close()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

дефер этот надо делать сразу после успешного открытия файла

сейчас, если мы вышли в 34 или 29 строек - файл останется открытым

outFile, err := os.Create(toPath)

if err != nil {
return err

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)

defer outFile.Close()

if offset > 0 {
inFile.Seek(offset, io.SeekStart)

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()

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")

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нейминг слабый

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants