renameSync method

  1. @override
File renameSync(
  1. String newPath
)
override

Synchronously renames this file system entity.

Returns a FileSystemEntity instance for the renamed entity.

Implementation

@override
File renameSync(String newPath) {
  final file = assertIsFile(_fs, path, 'Cannot rename file to "$newPath"');

  final newFile = MemoryFile._(_fs, newPath);
  newFile.createSync();

  _fs.remove(path); // Remove the old file.
  _fs.set(newPath, file); // Copy the new file over

  return newFile;
}