mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-23 17:33:51 +02:00
fix(computers): delete large agent files without downloading
Hash remote files through confined descriptors in bounded chunks before editor mutations. Preserve the remote compare-and-swap removal check and read-size cap; cover a real 17 MiB file, stale deletion, and path confinement. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
03542b0845
commit
ec80163f2f
6 files changed
+73
-4
No files matched your search
@@ -143,6 +143,18 @@ try:
|
||||
finally:os.close(parentfd)
|
||||
if not stat.S_ISDIR(info.st_mode) and not stat.S_ISREG(info.st_mode):fail('invalid')
|
||||
print(json.dumps({'name':name,'kind':'directory' if stat.S_ISDIR(info.st_mode) else 'file','size':info.st_size,'mtimeMs':info.st_mtime*1000}))
|
||||
elif act=='hash':
|
||||
parentfd,name=parent(path)
|
||||
try:fd=os.open(name,os.O_RDONLY|os.O_NOFOLLOW,dir_fd=parentfd)
|
||||
finally:os.close(parentfd)
|
||||
with os.fdopen(fd,'rb') as f:
|
||||
if not stat.S_ISREG(os.fstat(f.fileno()).st_mode):fail('invalid')
|
||||
h=hashlib.sha256();size=0
|
||||
while True:
|
||||
block=f.read(65536)
|
||||
if not block:break
|
||||
h.update(block);size+=len(block)
|
||||
print(json.dumps({'sha256':h.hexdigest(),'size':size}))
|
||||
elif act=='read':
|
||||
parentfd,name=parent(path)
|
||||
try:fd=os.open(name,os.O_RDONLY|os.O_NOFOLLOW,dir_fd=parentfd)
|
||||
|
||||
Reference in new issue
Block a user