@@ -799,20 +799,32 @@ enum _FileOperations {
799799 throw CocoaError . fileOperationError ( . fileReadNoSuchFile, src, dst, variant: bCopyFile ? " Copy " : " Link " )
800800 }
801801
802+ guard delegate. shouldPerformOnItemAtPath ( src, to: dst) else { return }
803+
802804 try dst. withNTPathRepresentation { pwszDestination in
803- if bCopyFile || faAttributes. dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT == FILE_ATTRIBUTE_REPARSE_POINT {
805+ if faAttributes. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY == FILE_ATTRIBUTE_DIRECTORY {
806+ do {
807+ try fileManager. createDirectory ( atPath: dst, withIntermediateDirectories: true )
808+ } catch {
809+ try delegate. throwIfNecessary ( error, src, dst)
810+ }
811+ for item in _Win32DirectoryContentsSequence ( path: src, appendSlashForDirectory: true ) {
812+ try linkOrCopyFile ( src. appendingPathComponent ( item. fileName) , dst: dst. appendingPathComponent ( item. fileName) , with: fileManager, delegate: delegate)
813+ }
814+ } else if bCopyFile || faAttributes. dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT == FILE_ATTRIBUTE_REPARSE_POINT {
804815 var ExtendedParameters : COPYFILE2_EXTENDED_PARAMETERS = . init( )
805816 ExtendedParameters . dwSize = DWORD ( MemoryLayout< COPYFILE2_EXTENDED_PARAMETERS> . size)
806- ExtendedParameters . dwCopyFlags = COPY_FILE_COPY_SYMLINK | COPY_FILE_NO_BUFFERING | COPY_FILE_OPEN_AND_COPY_REPARSE_POINT
807- if faAttributes. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY == FILE_ATTRIBUTE_DIRECTORY {
808- ExtendedParameters . dwCopyFlags |= COPY_FILE_DIRECTORY
809- }
817+ ExtendedParameters . dwCopyFlags = COPY_FILE_FAIL_IF_EXISTS | COPY_FILE_COPY_SYMLINK | COPY_FILE_NO_BUFFERING | COPY_FILE_OPEN_AND_COPY_REPARSE_POINT
810818
811- guard SUCCEEDED ( CopyFile2 ( pwszSource, pwszDestination, & ExtendedParameters) ) else {
812- throw CocoaError . copyFileError ( GetLastError ( ) , src, dst)
819+ if FAILED ( CopyFile2 ( pwszSource, pwszDestination, & ExtendedParameters) ) {
820+ try delegate . throwIfNecessary ( GetLastError ( ) , src, dst)
813821 }
814822 } else {
815- try fileManager. createSymbolicLink ( atPath: dst, withDestinationPath: src)
823+ do {
824+ try fileManager. createSymbolicLink ( atPath: dst, withDestinationPath: src)
825+ } catch {
826+ try delegate. throwIfNecessary ( error, src, dst)
827+ }
816828 }
817829 }
818830 }
0 commit comments