feat: Improve VFS rename and copy operations
- Return FSEntry from `rename` and `copy` operations in VFS to provide more information about the result. This allows access to metadata after a successful rename or copy. - Update `LocalVFS` and `NestedVFS` implementations to return the appropriate FSEntry objects after successful rename and copy operations.
This commit is contained in:
@@ -63,8 +63,8 @@ mut:
|
||||
// Common operations
|
||||
exists(path string) bool
|
||||
get(path string) !FSEntry
|
||||
rename(old_path string, new_path string) !
|
||||
copy(src_path string, dst_path string) !
|
||||
rename(old_path string, new_path string) !FSEntry
|
||||
copy(src_path string, dst_path string) !FSEntry
|
||||
move(src_path string, dst_path string) !FSEntry
|
||||
delete(path string) !
|
||||
|
||||
|
||||
@@ -227,7 +227,7 @@ pub fn (myvfs LocalVFS) get(path string) !FSEntry {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (myvfs LocalVFS) rename(old_path string, new_path string) ! {
|
||||
pub fn (myvfs LocalVFS) rename(old_path string, new_path string) !FSEntry {
|
||||
abs_old := myvfs.abs_path(old_path)
|
||||
abs_new := myvfs.abs_path(new_path)
|
||||
|
||||
@@ -241,9 +241,16 @@ pub fn (myvfs LocalVFS) rename(old_path string, new_path string) ! {
|
||||
os.mv(abs_old, abs_new) or {
|
||||
return error('Failed to rename ${old_path} to ${new_path}: ${err}')
|
||||
}
|
||||
metadata := myvfs.os_attr_to_metadata(new_path) or {
|
||||
return error('Failed to get metadata: ${err}')
|
||||
}
|
||||
return LocalFSEntry{
|
||||
path: new_path
|
||||
metadata: metadata
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (myvfs LocalVFS) copy(src_path string, dst_path string) ! {
|
||||
pub fn (myvfs LocalVFS) copy(src_path string, dst_path string) !FSEntry {
|
||||
abs_src := myvfs.abs_path(src_path)
|
||||
abs_dst := myvfs.abs_path(dst_path)
|
||||
|
||||
@@ -255,6 +262,13 @@ pub fn (myvfs LocalVFS) copy(src_path string, dst_path string) ! {
|
||||
}
|
||||
|
||||
os.cp(abs_src, abs_dst) or { return error('Failed to copy ${src_path} to ${dst_path}: ${err}') }
|
||||
metadata := myvfs.os_attr_to_metadata(abs_dst) or {
|
||||
return error('Failed to get metadata: ${err}')
|
||||
}
|
||||
return LocalFSEntry{
|
||||
path: dst_path
|
||||
metadata: metadata
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (myvfs LocalVFS) move(src_path string, dst_path string) !FSEntry {
|
||||
|
||||
@@ -142,7 +142,7 @@ pub fn (mut self NestedVFS) get(path string) !vfscore.FSEntry {
|
||||
return impl.get(rel_path)
|
||||
}
|
||||
|
||||
pub fn (mut self NestedVFS) rename(old_path string, new_path string) ! {
|
||||
pub fn (mut self NestedVFS) rename(old_path string, new_path string) !vfscore.FSEntry {
|
||||
mut old_impl, old_rel_path := self.find_vfs(old_path)!
|
||||
mut new_impl, new_rel_path := self.find_vfs(new_path)!
|
||||
|
||||
@@ -150,10 +150,11 @@ pub fn (mut self NestedVFS) rename(old_path string, new_path string) ! {
|
||||
return error('Cannot rename across different VFS implementations')
|
||||
}
|
||||
|
||||
return old_impl.rename(old_rel_path, new_rel_path)
|
||||
renamed_file := old_impl.rename(old_rel_path, new_rel_path)!
|
||||
return renamed_file
|
||||
}
|
||||
|
||||
pub fn (mut self NestedVFS) copy(src_path string, dst_path string) ! {
|
||||
pub fn (mut self NestedVFS) copy(src_path string, dst_path string) !vfscore.FSEntry {
|
||||
mut src_impl, src_rel_path := self.find_vfs(src_path)!
|
||||
mut dst_impl, dst_rel_path := self.find_vfs(dst_path)!
|
||||
|
||||
@@ -164,8 +165,9 @@ pub fn (mut self NestedVFS) copy(src_path string, dst_path string) ! {
|
||||
// Copy across different VFS implementations
|
||||
// TODO: Q: What if it's not file? What if it's a symlink or directory?
|
||||
data := src_impl.file_read(src_rel_path)!
|
||||
dst_impl.file_create(dst_rel_path)!
|
||||
return dst_impl.file_write(dst_rel_path, data)
|
||||
new_file := dst_impl.file_create(dst_rel_path)!
|
||||
dst_impl.file_write(dst_rel_path, data)!
|
||||
return new_file
|
||||
}
|
||||
|
||||
pub fn (mut self NestedVFS) move(src_path string, dst_path string) !vfscore.FSEntry {
|
||||
|
||||
Reference in New Issue
Block a user