Showing posts with label filesystem. Show all posts
Showing posts with label filesystem. Show all posts

Wednesday, September 2, 2009

PHP Get Oldest File

I was looking around to make sure there wasn't some sort of built-in function in PHP now for determining the oldest file in a directory. I didn't find a built-in function that returns the oldest file, but I found plenty of user functions that were not what I was looking for.

So, I wrote my own old file getter function. The function will accept either an array of file paths or a string which will be passed to glob in order to get an array of file paths. The function returns the oldest file found.

function oldest_file($dir)
{
if(is_string($dir))
{
$dir = glob($dir);
}
$oldest = array_shift($dir);
foreach($dir as $file)
{
if(filemtime($file) < filemtime($oldest))
{
$oldest = $file;
}
}
return $oldest;
}

Friday, July 18, 2008

Byte Chart w/ Large Numbers

Chart showing filesizes

It took me entirely too long to lookup how many digits were in a Petabyte, so after some hunting I put together this neatly organized chart displaying up to the 25th digit or 1024^8th place.
I tried to arrange the data in such a way that the chart shouldn't need much explaination or any legends or keys.

It shows
  • kibibyte / kilobyte filesize
  • mebibyte / megabyte filesize
  • gibibyte / gigabyte filesize
  • tebibyte / terabyte filesize
  • pebibyte / petabyte filesize
  • exbibyte / exabyte filesize
  • zebibyte / zettabyte filesize
  • yobibyte / yottabyte filesize


I noticed an easy way to remember which digit a Yottabyte starts with, Y is the 25th letter in the English alphabet & 25 is the digit a Yottabyte starts at. The same goes for P and Petabyte.

Wednesday, February 13, 2008

SVN: Can't open file '/format' Permission denied

I setup a Subversion repository on my Ubuntu system yesterday. Everything went smoothly for the most part.

I installed the Subversion package with the following command. Included in the package was svn, svnadmin, & svnserve.
sudo apt-get install subversion


I added a new subversion user & group. I added the new subversion user, and myself, to the subversion group.
sudo useradd --password pass subversion
sudo groupadd subversion
sudo adduser subversion subversion
sudo adduser me subversion


I created a repository, changed ownerships, & permissions.
sudo svnadmin create /svn/myrepos
sudo chown -R me:subversion /svn/myrepos
sudo chmod -R 0770 /svn/myrepos


I modified the repositories conf/passwd and conf/svnserv.conf files to allow read-only access by anonymous users & write access for me.

I went in and modified certain files like conf/passwd & conf.svnserv.conf to 0440 (owner & group read-only)

I started svnserve in the /svn directory as the subversion user.
sudo su subversion
svnserve -d -r /svn


But when trying to checkout the repository with Tortoise SVN on my Windows machine, I kept getting an error similar to the following.
Error Can't open file '/svn/format': Permission denied


Even when I chmod'ed the format file to 0777, I still got the error.

Come to find out, it really had little to do with that file directly. What it did have to do with was the permissions of the user that started svnserve & the directory svnserve was told to use as the repository root.

/svn had 0760 permissions, as soon as I gave my subversion group execute permissions so the subversion user who is a member of the subversion group & is starting the server could execute, it worked like a charm.
sudo chmod 0770 /svn