<?php
	const TMPDIR = "/tmp/tasuke_tmp/";

	function makeLockFile($tempdir, $sid) {
//		if(empty($tempdir)) { return; }
		$fpath = _getLockFilePath($tempdir, $sid);
		touch($fpath);
	}
	function removeLockFile($tempdir, $sid) {
//		if(empty($tempdir)) { return; }
		$fpath = _getLockFilePath($tempdir, $sid);
		if(file_exists($fpath)) { exec("rm $fpath"); }
	}
	function _getLockFilePath($tempdir, $sid) {
		if(empty($tempdir)) { $tempdir = TMPDIR; }
		return sprintf("%s/%s.lock", $tempdir, $sid);
	}
	function getJobCount($tempdir, $sid) {
		if(empty($tempdir)) { $tempdir = TMPDIR; }
		$snum = exec("ls $tempdir | wc -l" );
		$sflg = exec("ls $tempdir | grep $sid");
        	return array('sid' => $sid, 'snum' => $snum, 'sflg' => $sflg);
	}
	function isValidSession($tempdir, $sid) {
		$flg = false;
		$return_array = getJobCount($tempdir, $sid);
		if(!empty($return_array['sflg'])) { $flg = true; }
		return $flg;
	}
?>
