How can I hide .SVN directories from PHP

2019-05-30 13:27发布

问题:

I am using SVN to manage a copy of my web site. The site runs a typo3 installation, which uses PHP to create the backend.

The problem is, all the stupid .SVN folders show up in the directory listing of PHP. I DO NOT mean the build in apache listing. I mean a directoy listing created by the PHP backend.

So, is there any way to hide special directories from PHP?

[NOTE] Changing the PHP source code is not an option. Typo3 is too big, and each extensions uses its own code. Would be much more effort than an SVN export script.

Chris

PS: I do not want to setup a svn export --> web_root just to get rid of the files. And I know that I can prevent apache from serving the .SVN directories, I did that. But they still show up in the backend, when browsing the directory tree (which is created by PHP). And they are very annoying...

回答1:

This is difficult, since you will have to change behavior of something somewhere between the filesystem and Typo3. You have:

Filesystem → Operating System → PHP → Typo3

The files must stay in the filesystem and must stay visible by the operating system, so you can use SVN. Changing Typo3 is not an option for you, and changing PHP has many other major undesirable consequences that you should avoid. So, what you have left is to insert something in between OS→PHP or PHP→Typo3.

The first case is actually possible, depending on what operating system you use, and if you have administrator (root) access. FUSE is part of the Linux kernel, and is also available for many other operating systems. Then, with fuse, you may install a filter like rofs-filtered, that allows you to filter which files and directories are visible in a mounted volume. You use it to create a filesystem that mirrors your SVN checkout directory, filtering the .svn directories.



回答2:

So, is there any way to hide special directories from PHP?

No.

As long as the user PHP is run under has read access to the directory it will always produce all the files/directories in that directory. There is no way to hide files from certain processes, were this possible writing a root kit to hide from ls and other file system tools would be a lot easier.

The option you would want/need is a way to define files that Typo3 ignores, and have it be system wide and thus used by the extensions as well. You have specified however that you do not want to change the source code, and do not want to do svn export.

You are thus stuck with the .svn directories.



回答3:

The short answer is "Not easily, simply, or sanely".

Run the website from an export of SVN, not a checkout, instead.



回答4:

Try this.

<locationmatch "/.svn/">
    order allow,deny
    deny from all
</locationmatch> 

Btw in your loop in PHP you can do a logic check to see if the filename is not ".svn", usually PHP directory tools do that to exclude "." and ".." directories.



回答5:

The problem is, all the stupid .SVN folders show up in the directory listing of PHP. I DO NOT mean the build in apache listing. I mean a directoy listing created by the PHP backend.

What application is doing the directory listing? Have you considered looking into the code of the PHP backend and adding something to prevent the display of the .svn directories?



回答6:

Just find or write a very simple application that will synchronize your current directory with a new directory that will be exposed to the Web. You could have a service that watches for changes or use something like an rsync with exclusions or what have you. This would be much simpler since, based on another question, you are on Windows.



回答7:

ther's an extension called np_subversion which will take care of fileadmin changes via subversion. As a nice plus it will hide folders for you



回答8:

I do not want to setup a svn export --> web_root just to get rid of the files

Are you sure? That’s how SVN is designed: you check code out of SVN to work on it, and export code from SVN to deploy it. If you don’t like that, then SVN probably isn’t the right choice. As gahooa said, maybe switch to Git?

It’s a bit like saying “I want to save my Word document, but I don’t want this stupid .doc file showing up on my computer.” That’s just how the software works.



回答9:

Sara Golemon's Runkit can do this. You can remap functions like glob(). However, I am not sure if it's a good idea to run it in a production server.



回答10:

If you don't need the .svn folders, you can just delete them.

find ./ -name ".svn" | xargs rm -f *.svn