@@ -55,7 +55,7 @@ private async Task<IFile> ResolveTemplateFileAsync(
5555 /// <summary>
5656 /// Recursively copy all assets from template folder to output folder.
5757 /// Excludes template file itself to avoid duplication.
58- /// Preserves folder structure using OwlCore.Storage recursive operations .
58+ /// Preserves folder structure using relative path resolution .
5959 /// </summary>
6060 /// <param name="templateFolder">Source template folder</param>
6161 /// <param name="outputFolder">Destination output folder</param>
@@ -71,18 +71,26 @@ private async Task CopyTemplateAssetsAsync(
7171 // Gap #7 resolution: Filter files and exclude template file by ID comparison
7272 await foreach ( var item in recursiveFolder . GetItemsAsync ( StorableType . File ) )
7373 {
74- if ( item is not IFile file )
74+ if ( item is not IChildFile file )
7575 continue ;
7676
7777 // Exclude the template file itself
7878 if ( file . Id == templateFile . Id )
7979 continue ;
8080
81- // Copy asset to output folder (overwrite silently per Gap #6)
82- if ( outputFolder is IModifiableFolder modifiableOutput )
83- {
84- await modifiableOutput . CreateCopyOfAsync ( file , overwrite : true ) ;
85- }
81+ // Get relative path from template folder to file (preserves folder structure)
82+ var relativePath = await templateFolder . GetRelativePathToAsync ( file ) ;
83+
84+ // Create file at relative path in output folder (creates necessary parent folders)
85+ var targetStorable = await outputFolder . CreateByRelativePathAsync ( relativePath , StorableType . File , overwrite : true ) ;
86+
87+ if ( targetStorable is not IFile targetFile )
88+ throw new InvalidOperationException ( $ "Created item at '{ relativePath } ' is not a file.") ;
89+
90+ // Copy file content
91+ using var sourceStream = await file . OpenReadAsync ( ) ;
92+ using var targetStream = await targetFile . OpenStreamAsync ( FileAccess . Write ) ;
93+ await sourceStream . CopyToAsync ( targetStream ) ;
8694 }
8795 }
8896
@@ -116,4 +124,4 @@ private async Task<string> RenderTemplateAsync(
116124 return html ;
117125 }
118126 }
119- }
127+ }
0 commit comments