#111081Copying a folder in filelist does not copy metadata of contained files (while single file copy does)
Description
When a user copies a folder via the filelist module (copy → paste into another folder), the metadata (title, description, alternative, etc.) of all contained files is lost. Copying the same files individually works correctly and preserves metadata.
*Steps to reproduce*
1. Upload a few files to fileadmin/some_folder/
2. Edit their metadata (set title and description)
3. Copy the folder some_folder/ and paste it into another storage location
4. Open the copied files and check their metadata: title and description are empty
*Expected behaviour*
Metadata (title, description, alternative, etc.) of contained files should be copied to the new files — exactly as it happens when copying a single file.
Actual behaviour
- The physical files are copied on disk.
- The copied files are not indexed into sys_file during the operation.
- When later indexed (lazy/on browse or via the File Storage Indexing scheduler task), MetaDataRepository::createMetaDataRecord() creates an empty sys_file_metadata record (only file uid + timestamps).
- All manually-set metadata fields are lost.
*Root cause*
There is an inconsistency between ResourceStorage::copyFile() and ResourceStorage::copyFolder():
copyFile() (typo3/sysext/core/Classes/Resource/ResourceStorage.php:1959-1965) explicitly copies the source file’s metadata inline:
if ($file instanceof File && $newFileObject !== null) {
$metaDataAspect = $newFileObject->getMetaData();
$metaDataAspect->add(array_replace($file->getMetaData()->get(), $metaDataAspect->get()));
$metaDataAspect->save();
}
copyFolder() (ResourceStorage.php:2327-2367) does not:
- It only calls $this->driver->copyFolderWithinStorage() (line 2356), which performs a raw filesystem copy (LocalDriver::copyFolderWithinStorage() at Driver/LocalDriver.php:1075, using PHP copy()).
- It never calls getAllFileObjectsInFolder() to enumerate contained files.
- It never calls the indexer to create sys_file records.
- It never copies sys_file_metadata records.
By contrast, moveFolder() (line 2265) does iterate contained files via getAllFileObjectsInFolder() (line 2276) and calls $this->getIndexer()->updateIndexEntry($fileObject) (line 2296). copyFolder() skips all of this.
The AfterFolderCopiedEvent is dispatched (lines 2362-2364) but:
- It carries no source→target file identifier mapping (so a listener would have no way to associate copied files with their sources).
- It has zero registered listeners anywhere in the core (confirmed across all sysext *.yaml and *.php files).
The driver-level copyFolderWithinStorage() also returns only a boolean true, unlike moveFolderWithinStorage() which returns an old→new identifier $identifierMap.
*Additional context*
- There is an existing functional test copyFileCopiesMetadata() in typo3/sysext/core/Tests/Functional/Resource/StorageRepositoryTest.php:543 verifying metadata copy for single files, but no equivalent test for folder copy.
- copyFolderBetweenStorages() is not implemented (throws NotImplementedMethodException), so this only affects same-storage folder copy.
*Suggested fix*
@ResourceStorage::copyFolder()@ should, after the driver copies the folder:
1. Enumerate source files via getAllFileObjectsInFolder($folderToCopy).
2. For each source file, locate the corresponding copied file in the target folder and either call $this->copyFile(...) (which already handles metadata) or replicate the metadata-copy logic from copyFile() lines 1959-1965.
3. The driver’s copyFolderWithinStorage() should return an old→new identifier map (like moveFolderWithinStorage() already does) so the storage layer can associate copied files with their sources.
Alternatively, copyFolder() could loop over source files before the driver call and call copyFile() for each file individually, leaving only directory creation to the driver.
Reviews 1
Related issues 1
History 15
-
Gerrit Code Review pushed patch set 1 for main to change 96846 status
NewUnder Review <span data-processor="relativetime" data-value="2026-10-19T05:56:31+00:00" > 10/19/26, 05:56 </span> -
Wolfgang Klinger changed Related to #111137 <span data-processor="relativetime" data-value="2026-10-19T06:11:36+00:00" > 10/19/26, 06:11 </span>
-
Gerrit Code Review pushed patch set 2 for main to change 96846 <span data-processor="relativetime" data-value="2026-10-20T16:14:33+00:00" > 10/20/26, 16:14 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 96846 <span data-processor="relativetime" data-value="2026-11-11T10:05:58+00:00" > 11/11/26, 10:05 </span>
-
Gerrit Code Review pushed patch set 4 for main to change 96846 <span data-processor="relativetime" data-value="2026-11-12T21:13:25+00:00" > 11/12/26, 21:13 </span>