Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive deletion of directories #47

Open
skurrilewelt opened this issue Aug 26, 2024 · 5 comments
Open

Recursive deletion of directories #47

skurrilewelt opened this issue Aug 26, 2024 · 5 comments

Comments

@skurrilewelt
Copy link

Tried to remove a directory structure like this:

-root
--content
----file1
----file2
----subdir
------file4
------file3

and the method FtpClient::removeDir(directory) doesn't jumps in to the subdir and as a result the directory content will not be deleted as intended.

Change line 373 in mentioned class to:
$this->removeDir($fileInfo['path']);
will solve this issue. Or miss I something?

@AmraniCh
Copy link
Member

Hey, thanks for opening this issue.

print_r($this->isDir("root/content/subdir"));

Check this and see what result you will get, it must be true, otherwise we will use another method listDirDetails to see details about the file root/content/subdir and guess what the problem with it!

@skurrilewelt
Copy link
Author

I think, it is obvious. You can't call rmdir because it won't delete directories which are not empty.

@AmraniCh
Copy link
Member

AmraniCh commented Aug 30, 2024

The removeDir method should delete everything within a directory whether it's a file or a directory.

@AmraniCh AmraniCh closed this as completed Oct 2, 2024
@skurrilewelt
Copy link
Author

Don't know, why you closed this without looking into your code:

public function removeDir(string $directory) : bool
    {
        $list = array_reverse($this->listDirDetails($directory, true));
        foreach ($list as $fileInfo) {
            if ($fileInfo['type'] === 'file') {
                $this->wrapper->delete($fileInfo['path']);
                continue;
            }
            $this->wrapper->rmdir($fileInfo['path']);
        }

        return $this->wrapper->rmdir($directory);
    }

There is the recursive call to removeDir missing, in fact you call rmdir which won't works

@AmraniCh AmraniCh reopened this Oct 3, 2024
@AmraniCh
Copy link
Member

AmraniCh commented Oct 3, 2024

Hi @skurrilewelt

I closed the issue because of no response from your end, and I explained that the removeDir should recursively remove all the files and directories, and you have not provided any additional information about your issues like the directory structure or the error message.

Please share the output of this command:

 $list = array_reverse($this->listDirDetails($directory, true));
print($list);

You have to know that some FTP servers may have different implementations of the FTP specification and its extensions, so we are not expecting our library methods to work perfectly with all FTP servers.

If you share additional info we can guess what your FTP server is doing differently to update our code and finally fix the issue.

thanks for your understanding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants