This is driving me nuts. I have some functions to make and delete directories which I've used for ages and had no problems with. The rmdir function I have is a little different as it has to first delete all the files inside. However in this one case it just won't work and I'm getting warnings every time. It keeps saying the folder isn't empty but it always is when I check it with an FTP client.
Here are the functions I use.
The code where it goes wrong (bit messy).
The error
Here are the functions I use.
PHP:
function vmd_mkdir($dir)
{
mkdir($dir, 0777, true);
if(!is_dir($dir))
{
die('Unable to create directory \''.$dir.'\'');
}
}
function vmd_rmdir($dir)
{
if($handle = opendir($dir))
{
while(false !== ($obj = readdir($handle)))
{
if($obj != '.' && $obj != '..')
{
if(filetype($dir.'/'.$obj) == 'dir') vmd_rmdir($dir.'/'.$obj);
else unlink($dir.'/'.$obj);
}
}
closedir($handle);
rmdir($dir);
}
}
The code where it goes wrong (bit messy).
PHP:
if($err == 1)
{
echo 'ERROR: File Mismatch. Checksum failed on file \''.$mdlname.'\' ('.$checksum.' -> '.$checksum_cval.'). Check that file is correct.';
decompile_log($udir, 'decompile.php ERROR: Checksum failed on file \''.$mdlname.'\' ('.$checksum.' -> '.$checksum_cval.').');
}
else
{
vmd_mkdir('models/'.$checksum);
$bin_mdl = vmd_fread('temp/'.$udir.'/'.$mdlname.'.mdl');
$mdl = vmd_qc($bin_mdl, $mdlname);
$vvd = vmd_verts($bin_vvd); //Extract vertex pool.
$vtx = vmd_tris($bin_vtx); //Assemble faces in correct draw order as a triangle strip.
if($phy)
{
$phy = vmd_phy($bin_phy);
$mdl[0] .= $phy[0];
}
$meshnames = vmd_smd($vvd, $vtx, $mdl[4], $checksum, $mdl[1], $mdlname);
vmd_rmdir('temp/'.$udir);
$dfile = new ZipArchive;
if($dfile->open('download/'.$checksum.'/'.$mdlname.'.zip', ZipArchive::CREATE) === TRUE)
{
$dfile->addFromString($mdlname.'.qc', $mdl[0]);
foreach($meshnames as $meshname)
{
$dfile->addFile('models/'.$checksum.'/'.$meshname, $meshname);
}
$dfile->close();
echo '<a href="download/'.$checksum.'/'.$mdlname.'.zip" target="_blank">Download</a>';
decompile_log($udir, 'decompile.php SUCCESS: User decompiled a new model (download/'.$checksum.'/'.$mdlname.'.zip).');
}
else
{
echo 'ERROR: Could not create file archive for download.';
decompile_log($udir, 'decompile.php ERROR: Could not create file archive for download (download/'.$checksum.'/'.$mdlname.'.zip).');
}
vmd_rmdir('models/'.$checksum);
}
The error
Code:
Warning: unlink(models/09006a36/.nfs00000000008b48ca00000746) [function.unlink]: Device or resource busy in lib_vmd.php on line 29
Warning: rmdir(models/09006a36) [function.rmdir]: Directory not empty in lib_vmd.php on line 33