Skip to content

Commit b94dcd4

Browse files
committed
add validation for fromPath
1 parent 0c6ec41 commit b94dcd4

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

hw07_file_copying/copy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ func Copy(fromPath, toPath string, offset, limit int64) error {
4545
if err != nil {
4646
return err
4747
}
48+
if fInfo.IsDir() {
49+
return ErrUnsupportedFile
50+
}
4851
if offset > fInfo.Size() {
4952
return ErrOffsetExceedsFileSize
5053
}

hw07_file_copying/copy_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ func TestCopy(t *testing.T) {
1717
limit int64
1818
err error
1919
}{
20+
{
21+
name: "path to source file is directory",
22+
fromPath: "testdata/",
23+
toPath: "testdata/input2.txt",
24+
validCopyPath: "testdata/out_offset0_limit0.txt",
25+
offset: 0,
26+
limit: 0,
27+
err: ErrUnsupportedFile,
28+
},
2029
{
2130
name: "paths to source and destination files are the same",
2231
fromPath: "testdata/input.txt",

0 commit comments

Comments
 (0)