chore(web_file_system): sync changes from open_xml including idb_block_store, getAsBlob, and tests
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
import 'package:file/file.dart';
|
||||
import 'package:web_file_system/src/backend/idb_inode_service.dart';
|
||||
import '../backend/idb_inode_service.dart';
|
||||
import '../web_file_system.dart';
|
||||
|
||||
class WebLink extends FileSystemEntity implements Link {
|
||||
@@ -36,7 +35,7 @@ class WebLink extends FileSystemEntity implements Link {
|
||||
|
||||
// Write target path string to OPFS blob
|
||||
final stream = Stream.value(utf8.encode(target));
|
||||
final (blobId, _) = await _fs.opfs.writeBlob(stream);
|
||||
final blobId = await _fs.opfs.writeBlob(stream);
|
||||
|
||||
final parentPath = _fs.path.dirname(path);
|
||||
final parentInode = await _fs.resolvepath(parentPath);
|
||||
@@ -58,41 +57,7 @@ class WebLink extends FileSystemEntity implements Link {
|
||||
|
||||
@override
|
||||
void createSync(String target, {bool recursive = false}) {
|
||||
if (existsSync()) {
|
||||
throw FileSystemException(
|
||||
'Link already exists',
|
||||
path,
|
||||
const OSError('EEXIST', 17),
|
||||
);
|
||||
}
|
||||
|
||||
final parentPath = _fs.path.dirname(path);
|
||||
final parentType = _fs.typeSync(parentPath);
|
||||
if (parentType == FileSystemEntityType.notFound) {
|
||||
if (recursive) {
|
||||
_fs.directory(parentPath).createSync(recursive: true);
|
||||
} else {
|
||||
throw FileSystemException(
|
||||
'Cannot create link, path = \'$path\' (OS Error: No such file or directory, errno = 2)',
|
||||
path,
|
||||
);
|
||||
}
|
||||
} else if (parentType != FileSystemEntityType.directory) {
|
||||
throw FileSystemException(
|
||||
'Cannot create link, path = \'$path\' (OS Error: Not a directory, errno = 20)',
|
||||
path,
|
||||
);
|
||||
}
|
||||
|
||||
final pathBytes = utf8.encode(path);
|
||||
final targetBytes = utf8.encode(target);
|
||||
final request = Uint8List(4 + pathBytes.length + targetBytes.length);
|
||||
final bd = ByteData.sublistView(request);
|
||||
bd.setUint32(0, pathBytes.length, Endian.little);
|
||||
request.setRange(4, 4 + pathBytes.length, pathBytes);
|
||||
request.setRange(4 + pathBytes.length, request.length, targetBytes);
|
||||
|
||||
_fs.makeSyncCall(7, request);
|
||||
throw UnsupportedError('Sync not supported');
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -101,7 +66,7 @@ class WebLink extends FileSystemEntity implements Link {
|
||||
|
||||
// Write new blob
|
||||
final stream = Stream.value(utf8.encode(target));
|
||||
final (blobId, _) = await _fs.opfs.writeBlob(stream);
|
||||
final blobId = await _fs.opfs.writeBlob(stream);
|
||||
|
||||
await _fs.idb.updateInode(
|
||||
Inode(
|
||||
@@ -120,30 +85,7 @@ class WebLink extends FileSystemEntity implements Link {
|
||||
|
||||
@override
|
||||
void updateSync(String target) {
|
||||
final type = _fs.typeSync(path, followLinks: false);
|
||||
if (type == FileSystemEntityType.notFound) {
|
||||
throw FileSystemException(
|
||||
'Cannot update link, path = \'$path\' (OS Error: No such file or directory, errno = 2)',
|
||||
path,
|
||||
);
|
||||
}
|
||||
if (type != FileSystemEntityType.link) {
|
||||
throw FileSystemException(
|
||||
'Not a link',
|
||||
path,
|
||||
const OSError('EINVAL', 22),
|
||||
);
|
||||
}
|
||||
|
||||
final pathBytes = utf8.encode(path);
|
||||
final targetBytes = utf8.encode(target);
|
||||
final request = Uint8List(4 + pathBytes.length + targetBytes.length);
|
||||
final bd = ByteData.sublistView(request);
|
||||
bd.setUint32(0, pathBytes.length, Endian.little);
|
||||
request.setRange(4, 4 + pathBytes.length, pathBytes);
|
||||
request.setRange(4 + pathBytes.length, request.length, targetBytes);
|
||||
|
||||
_fs.makeSyncCall(13, request);
|
||||
throw UnsupportedError('Sync not supported');
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -165,22 +107,7 @@ class WebLink extends FileSystemEntity implements Link {
|
||||
|
||||
@override
|
||||
String targetSync() {
|
||||
final type = _fs.typeSync(path, followLinks: false);
|
||||
if (type == FileSystemEntityType.notFound) {
|
||||
throw FileSystemException(
|
||||
'Cannot read link, path = \'$path\' (OS Error: No such file or directory, errno = 2)',
|
||||
path,
|
||||
);
|
||||
}
|
||||
if (type != FileSystemEntityType.link) {
|
||||
throw FileSystemException(
|
||||
'Not a link',
|
||||
path,
|
||||
const OSError('EINVAL', 22),
|
||||
);
|
||||
}
|
||||
final respBytes = _fs.makeSyncCall(8, utf8.encode(path));
|
||||
return utf8.decode(respBytes);
|
||||
throw UnsupportedError('Sync not supported');
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -205,33 +132,8 @@ class WebLink extends FileSystemEntity implements Link {
|
||||
}
|
||||
|
||||
@override
|
||||
Link renameSync(String newPath) {
|
||||
final type = _fs.typeSync(path, followLinks: false);
|
||||
if (type == FileSystemEntityType.notFound) {
|
||||
throw FileSystemException(
|
||||
'Cannot rename link, path = \'$path\' (OS Error: No such file or directory, errno = 2)',
|
||||
path,
|
||||
);
|
||||
}
|
||||
final newParentDir = _fs.path.dirname(newPath);
|
||||
if (_fs.typeSync(newParentDir) != FileSystemEntityType.directory) {
|
||||
throw FileSystemException(
|
||||
'Cannot rename link, path = \'$path\' (OS Error: No such file or directory, errno = 2)',
|
||||
path,
|
||||
);
|
||||
}
|
||||
|
||||
final pathBytes = utf8.encode(path);
|
||||
final newPathBytes = utf8.encode(newPath);
|
||||
final request = Uint8List(4 + pathBytes.length + newPathBytes.length);
|
||||
final bd = ByteData.sublistView(request);
|
||||
bd.setUint32(0, pathBytes.length, Endian.little);
|
||||
request.setRange(4, 4 + pathBytes.length, pathBytes);
|
||||
request.setRange(4 + pathBytes.length, request.length, newPathBytes);
|
||||
|
||||
_fs.makeSyncCall(12, request);
|
||||
return WebLink(_fs, newPath);
|
||||
}
|
||||
Link renameSync(String newPath) =>
|
||||
throw UnsupportedError('Sync not supported');
|
||||
|
||||
@override
|
||||
Future<FileSystemEntity> delete({bool recursive = false}) async {
|
||||
@@ -241,16 +143,8 @@ class WebLink extends FileSystemEntity implements Link {
|
||||
}
|
||||
|
||||
@override
|
||||
void deleteSync({bool recursive = false}) {
|
||||
final type = _fs.typeSync(path, followLinks: false);
|
||||
if (type == FileSystemEntityType.notFound) {
|
||||
throw FileSystemException(
|
||||
'Cannot delete link, path = \'$path\' (OS Error: No such file or directory, errno = 2)',
|
||||
path,
|
||||
);
|
||||
}
|
||||
_fs.makeSyncCall(6, utf8.encode(path));
|
||||
}
|
||||
void deleteSync({bool recursive = false}) =>
|
||||
throw UnsupportedError('Sync not supported');
|
||||
|
||||
@override
|
||||
Future<bool> exists() async {
|
||||
@@ -263,15 +157,13 @@ class WebLink extends FileSystemEntity implements Link {
|
||||
}
|
||||
|
||||
@override
|
||||
bool existsSync() {
|
||||
return _fs.typeSync(path, followLinks: false) == FileSystemEntityType.link;
|
||||
}
|
||||
bool existsSync() => throw UnsupportedError('Sync not supported');
|
||||
|
||||
@override
|
||||
Future<FileStat> stat() async => (await _fs.stat(path));
|
||||
|
||||
@override
|
||||
FileStat statSync() => _fs.statSync(path);
|
||||
FileStat statSync() => throw UnsupportedError('Sync not supported');
|
||||
|
||||
@override
|
||||
Uri get uri => Uri.parse(path);
|
||||
@@ -292,10 +184,21 @@ class WebLink extends FileSystemEntity implements Link {
|
||||
Link get absolute => WebLink(_fs, _fs.path.absolute(path));
|
||||
|
||||
@override
|
||||
Future<String> resolveSymbolicLinks() => _fs.resolveSymbolicLinks(path);
|
||||
Future<String> resolveSymbolicLinks() async {
|
||||
// If we are a link, return target? No, resolveSymbolicLinks follows all the way to canonical path.
|
||||
// For now, simpler: resolve path logic.
|
||||
final targetPath = await target();
|
||||
// If target is relative, resolve against directory. This gets complex.
|
||||
// MVP: Return target path raw? No, contract says "path with all symbolic links resolved".
|
||||
// This requires full traversal logic.
|
||||
// For MVP just return the path as we stored it if it's absolute, or join if relative.
|
||||
if (_fs.path.isAbsolute(targetPath)) return targetPath;
|
||||
return _fs.path.normalize(_fs.path.join(dirname, targetPath));
|
||||
}
|
||||
|
||||
@override
|
||||
String resolveSymbolicLinksSync() => _fs.resolveSymbolicLinksSync(path);
|
||||
String resolveSymbolicLinksSync() =>
|
||||
throw UnsupportedError('Sync not supported');
|
||||
|
||||
@override
|
||||
Stream<FileSystemEvent> watch({
|
||||
|
||||
Reference in New Issue
Block a user