fix(ftp): recursively delete directory contents before RMD
Problem: FTP's RMD command fails with '550 Directory not empty' if the directory has any contents. Unlike the S3 adapter which uses `aws s3 rm --recursive`, FTP has no protocol-level recursive delete. Solution: emit a Python rmtree helper inside the ftpcmd script that walks the directory via MLSD, recursively deletes children (DELE for files, rmtree for subdirs), then sends RMD on the now-empty directory.
This commit is contained in:
parent
c90c5fcfaa
commit
b7f475787e
1 changed files with 10 additions and 1 deletions
|
|
@ -496,7 +496,16 @@ M.perform_action = function(action, cb)
|
||||||
local res = M.parse_url(action.url)
|
local res = M.parse_url(action.url)
|
||||||
local ftp_path = ftp_abs_path(res)
|
local ftp_path = ftp_abs_path(res)
|
||||||
if action.entry_type == 'directory' then
|
if action.entry_type == 'directory' then
|
||||||
ftpcmd(res, { string.format('ftp.voidcmd(%q)', 'RMD ' .. ftp_path) }, cb)
|
ftpcmd(res, {
|
||||||
|
'def rmtree(f, p):',
|
||||||
|
' for name, facts in f.mlsd(p):',
|
||||||
|
' if name in (".", ".."): continue',
|
||||||
|
' child = p.rstrip("/") + "/" + name',
|
||||||
|
' if facts["type"] == "dir": rmtree(f, child)',
|
||||||
|
' else: f.voidcmd("DELE " + child)',
|
||||||
|
' f.voidcmd("RMD " + p)',
|
||||||
|
string.format('rmtree(ftp, %q)', ftp_path),
|
||||||
|
}, cb)
|
||||||
else
|
else
|
||||||
ftpcmd(res, { string.format('ftp.voidcmd(%q)', 'DELE ' .. ftp_path) }, cb)
|
ftpcmd(res, { string.format('ftp.voidcmd(%q)', 'DELE ' .. ftp_path) }, cb)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue