/** * sugar_touch * Attempts to set the access and modification times of the file named in the filename * parameter to the value given in time . Note that the access time is always modified, * regardless of the number of parameters. If the file does not exist it will be created. * This method is basically a wrapper to the PHP touch method except that created files * may be set with the permissions specified in the configuration file (if set). * * @param $filename - The name of the file being touched. * @param $time - The touch time. If time is not supplied, the current system time is used. * @param $atime - If present, the access time of the given filename is set to the value of atime * @return boolean - Returns TRUE on success or FALSE on failure. * */ function sugar_touch($filename, $time = null, $atime = null) { $result = false; if (!empty($atime) && !empty($time)) { $result = @touch($filename, $time, $atime); } else { if (!empty($time)) { $result = @touch($filename, $time); } else { $result = @touch($filename); } } if (!$result) { $GLOBALS['log']->error("File {$filename} cannot be touched"); return $result; } if (!empty($GLOBALS['sugar_config']['default_permissions']['file_mode'])) { sugar_chmod($filename, $GLOBALS['sugar_config']['default_permissions']['file_mode']); } if (!empty($GLOBALS['sugar_config']['default_permissions']['user'])) { sugar_chown($filename); } if (!empty($GLOBALS['sugar_config']['default_permissions']['group'])) { sugar_chgrp($filename); } return true; }
/** * sugar_touch * Attempts to set the access and modification times of the file named in the filename * parameter to the value given in time . Note that the access time is always modified, * regardless of the number of parameters. If the file does not exist it will be created. * This method is basically a wrapper to the PHP touch method except that created files * may be set with the permissions specified in the configuration file (if set). * * @param $filename - The name of the file being touched. * @param $time - The touch time. If time is not supplied, the current system time is used. * @param $atime - If present, the access time of the given filename is set to the value of atime * @return boolean - Returns TRUE on success or FALSE on failure. * */ function sugar_touch($filename, $time = null, $atime = null) { if (!empty($GLOBALS['sugar_config']['default_permissions']['dir_mode'])) { $dirmode = $GLOBALS['sugar_config']['default_permissions']['dir_mode']; } else { $dirmode = null; } $result = sugar_mkdir(dirname($filename), $dirmode, true); if (!$result) { return $result; } if (!empty($atime) && !empty($time)) { $result = @touch($filename, $time, $atime); } else { if (!empty($time)) { $result = @touch($filename, $time); } else { $result = @touch($filename); } } if (!$result) { $GLOBALS['log']->error("File {$filename} cannot be touched"); return $result; } if (!empty($GLOBALS['sugar_config']['default_permissions']['file_mode'])) { sugar_chmod($filename, $GLOBALS['sugar_config']['default_permissions']['file_mode']); } if (!empty($GLOBALS['sugar_config']['default_permissions']['user'])) { sugar_chown($filename); } if (!empty($GLOBALS['sugar_config']['default_permissions']['group'])) { sugar_chgrp($filename); } // Add this to the file loader cache if (!SugarAutoLoader::fileExists($filename)) { SugarAutoLoader::addToMap($filename); } return true; }