/** * Executes a command and returns output lines in array. * * @param string $cmd Command to be executed. * * @return array Array on success. * @throws Horde_Vfs_Exception */ protected function _execute($cmd) { $cmd = str_replace('"-U%"', '-N', $cmd); $proc = proc_open($cmd, array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes); if (!is_resource($proc)) { // This should never happen. throw new Horde_Vfs_Exception('Failed to call proc_open().'); } $out = explode("\n", trim(stream_get_contents($pipes[1]))); $error = explode("\n", trim(stream_get_contents($pipes[2]))); $ret = proc_close($proc); // In some cases, (like trying to delete a nonexistant file), // smbclient will return success (at least on 2.2.7 version I'm // testing on). So try to match error strings, even after success. if ($ret != 0) { $err = ''; foreach ($error as $line) { if (strpos($line, 'Usage:') === 0) { $err = 'Command syntax incorrect'; break; } if (strpos($line, 'ERRSRV') !== false || strpos($line, 'ERRDOS') !== false) { $err = preg_replace('/.*\\((.+)\\).*/', '\\1', $line); if (!$err) { $err = $line; } break; } } if (!$err) { $err = $out ? $out[count($out) - 1] : $ret; } throw new Horde_Vfs_Exception($err); } // Check for errors even on success. $err = ''; foreach ($out as $line) { if (strpos($line, 'NT_STATUS_NO_SUCH_FILE') !== false || strpos($line, 'NT_STATUS_OBJECT_NAME_NOT_FOUND') !== false) { $err = Horde_Vfs_Translation::t("No such file"); break; } elseif (strpos($line, 'NT_STATUS_ACCESS_DENIED') !== false) { $err = Horde_Vfs_Translation::t("Permission Denied"); break; } } if ($err) { throw new Horde_Vfs_Exception($err); } return $out; }
/** * Rename a file or folder in the VFS. * * @param string $oldpath The old path to the file. * @param string $oldname The old filename. * @param string $newpath The new path of the file. * @param string $newname The new filename. * * @throws Horde_Vfs_Exception */ public function rename($oldpath, $oldname, $newpath, $newname) { $this->_connect(); if (strpos($newpath, '/') === false) { $parent = ''; $path = $newpath; } else { list($parent, $path) = explode('/', $newpath, 2); } if (!$this->isFolder($parent, $path)) { $this->autocreatePath($newpath); } $this->_db->query(sprintf('UPDATE %s SET vfs_path = ?, vfs_name = ?, vfs_modified = ? WHERE vfs_path = ? AND vfs_name = ?', $this->_params['table']), array($newpath, $newname, time(), $oldpath, $oldname)); if ($this->_db->affectedRows() == 0) { throw new Horde_Vfs_Exception('Unable to rename VFS file.'); } if (is_a($this->_recursiveSQLRename($oldpath, $oldname, $newpath, $newname), 'PEAR_Error')) { $this->_db->query(sprintf('UPDATE %s SET vfs_path = ?, vfs_name = ? WHERE vfs_path = ? AND vfs_name = ?', $this->_params['table']), array($oldpath, $oldname, $newpath, $newname)); throw new Horde_Vfs_Exception('Unable to rename VFS directory.'); } if (!@is_dir($this->_getNativePath($newpath))) { $this->autocreatePath($newpath); } if (!@rename($this->_getNativePath($oldpath, $oldname), $this->_getNativePath($newpath, $newname))) { $this->_db->query(sprintf('UPDATE %s SET vfs_path = ?, vfs_name = ? WHERE vfs_path = ? AND vfs_name = ?', $this->_params['table']), array($oldpath, $oldname, $newpath, $newname)); return PEAR::raiseError(Horde_Vfs_Translation::t("Unable to rename VFS file.")); } }
/** * Returns the plural translation of a message. * * @param string $singular The singular version to translate. * @param string $plural The plural version to translate. * @param integer $number The number that determines singular vs. plural. * * @return string The string translation, or the original string if no * translation exists. */ public static function ngettext($singular, $plural, $number) { self::$_domain = 'Horde_Vfs'; self::$_directory = '@data_dir@' == '@' . 'data_dir' . '@' ? __DIR__ . '/../../../locale' : '@data_dir@/Horde_Vfs/locale'; return parent::ngettext($singular, $plural, $number); }