skip to Main Content

As a side project, I want to create a package manager for PHP using Github repositories.

When I run my command:

absol pickup <git-repo>

Under the hood, I run the command with shell_exec:

shell_exec("git clone -q --depth=1 $git_repo $path");

And all works as expected.

Problem:

Now I’m trying to implement a command that will let me delete unwanted packages. When I try to delete files with the unlink function I get the error:

Warning: unlink(.gitobjectspackpack-83ff79c801011289eaee13a84795a6288641feec.idx): Permission denied

Is there a way to delete these files using PHP on Windows?

P.S. This is just a personal side project as a utility for more side projects. I’m fine with deleting packages manually if this problem cannot be resolved.

2

Answers


  1. Chosen as BEST ANSWER

    Ansh answer is not entirely correct, but it gave me a push to the right answer:

    shell_exec("git rm --cached path/to/file");
    

    Removed normal file (README.md) but the .git directory was still intact and this question focuses on removing the .git directory.

    shell_exec("cmd /c del path/to/file");
    

    This command worked, but I have modified it to delete the whole package directory.

    echo "Do you want to remove $package? (dir: '$path')";
    shell_exec("cmd /c rmdir /s $path"); // "/s" to delete recursively
    

  2. Since you’re dealing with Git-related files, consider using Git commands to delete the files. You can execute Git commands from PHP using shell_exec or other similar functions. For example-

    shell_exec("git rm --cached path/to/file");
    

    As a last resort, you can use the cmd.exe command prompt to delete the files. Use shell_exec to run the del command-

    shell_exec("cmd /c del path/to/file");
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search