@@ -111,19 +111,55 @@ void main() {
111111 expect (io.File (newPath).readAsBytesSync (), data);
112112 });
113113
114- test ('copy file to existing' , () {
114+ test ('copy file to existing file ' , () {
115115 final data = randomUint8List (1024 );
116116 final oldPath = '$tmp /file1' ;
117117 final newPath = '$tmp /file2' ;
118118 io.File (oldPath).writeAsBytesSync (data);
119119 io.File (newPath).writeAsStringSync ('Hello World!' );
120120
121- fileSystem.copyFile (oldPath, newPath);
121+ expect (
122+ () => fileSystem.copyFile (oldPath, newPath),
123+ throwsA (
124+ isA <PathExistsException >()
125+ .having ((e) => e.path1, 'path1' , newPath)
126+ .having (
127+ (e) => e.errorCode,
128+ 'errorCode' ,
129+ io.Platform .isWindows
130+ ? win32.ERROR_ALREADY_EXISTS
131+ : errors.eexist,
132+ ),
133+ ),
134+ );
135+ });
122136
123- expect (io.File (newPath).readAsBytesSync (), data);
137+ test ('copy file to existing link' , () {
138+ final data = randomUint8List (1024 );
139+ final oldPath = '$tmp /file1' ;
140+ final linkedFile = '$tmp /file2' ;
141+ final newPath = '$tmp /link' ;
142+ io.File (oldPath).writeAsBytesSync (data);
143+ io.File (linkedFile).writeAsStringSync ('Hello World' );
144+ io.Link (newPath).createSync (linkedFile);
145+
146+ expect (
147+ () => fileSystem.copyFile (oldPath, newPath),
148+ throwsA (
149+ isA <PathExistsException >()
150+ .having ((e) => e.path1, 'path1' , newPath)
151+ .having (
152+ (e) => e.errorCode,
153+ 'errorCode' ,
154+ io.Platform .isWindows
155+ ? win32.ERROR_ALREADY_EXISTS
156+ : errors.eexist,
157+ ),
158+ ),
159+ );
124160 });
125161
126- test ('copy to existant directory' , () {
162+ test ('copy to existing directory' , () {
127163 final data = randomUint8List (1024 );
128164 final oldPath = '$tmp /file1' ;
129165 final newPath = '$tmp /file2' ;
@@ -133,13 +169,15 @@ void main() {
133169 expect (
134170 () => fileSystem.copyFile (oldPath, newPath),
135171 throwsA (
136- isA <IOFileException >().having (
137- (e) => e.errorCode,
138- 'errorCode' ,
139- io.Platform .isWindows
140- ? 5 // ERROR_ACCESS_DENIED
141- : 21 , // EISDIR
142- ),
172+ isA <PathExistsException >()
173+ .having ((e) => e.path1, 'path1' , newPath)
174+ .having (
175+ (e) => e.errorCode,
176+ 'errorCode' ,
177+ io.Platform .isWindows
178+ ? win32.ERROR_ALREADY_EXISTS
179+ : errors.eexist,
180+ ),
143181 ),
144182 );
145183 });
0 commit comments