vfs_sql::mkdir creates missing base-directories (like /home, when createing /home/<user>) now automaticaly and updates the directory content if the directory already exists.

This commit is contained in:
Ralf Becker 2003-09-21 13:54:07 +00:00
parent 1df617bb0a
commit c30487281b

View File

@ -161,8 +161,7 @@
{ {
$sql = ' AND (('; $sql = ' AND ((';
reset ($this->meta_types); foreach ($this->meta_types as $num => $type)
while (list ($num, $type) = each ($this->meta_types))
{ {
if ($num) if ($num)
$sql .= ' AND '; $sql .= ' AND ';
@ -726,8 +725,7 @@
if (is_array ($memberships)) if (is_array ($memberships))
{ {
reset ($memberships); foreach ($memberships as $group_array)
while (list ($num, $group_array) = each ($memberships))
{ {
if ($owner_id == $group_array['account_id']) if ($owner_id == $group_array['account_id'])
{ {
@ -746,8 +744,7 @@
/* Add privileges from the groups this user belongs to */ /* Add privileges from the groups this user belongs to */
if (is_array ($memberships)) if (is_array ($memberships))
{ {
reset ($memberships); foreach ($memberships as $group_array)
while (list ($num, $group_array) = each ($memberships))
{ {
$rights |= $acl->get_rights ($group_array['account_id']); $rights |= $acl->get_rights ($group_array['account_id']);
} }
@ -1267,15 +1264,12 @@
); );
/* Next, we create all the directories below the initial directory */ /* Next, we create all the directories below the initial directory */
$ls = $this->ls (array( foreach($this->ls (array(
'string' => $f->fake_full_path, 'string' => $f->fake_full_path,
'relatives' => array ($f->mask), 'relatives' => array ($f->mask),
'checksubdirs' => True, 'checksubdirs' => True,
'mime_type' => 'Directory' 'mime_type' => 'Directory'
) )) as $entry)
);
while (list ($num, $entry) = each ($ls))
{ {
$newdir = ereg_replace ("^$f->fake_full_path", "$t->fake_full_path", $entry['directory']); $newdir = ereg_replace ("^$f->fake_full_path", "$t->fake_full_path", $entry['directory']);
$this->mkdir (array( $this->mkdir (array(
@ -1286,13 +1280,10 @@
} }
/* Lastly, we copy the files over */ /* Lastly, we copy the files over */
$ls = $this->ls (array( foreach($this->ls (array(
'string' => $f->fake_full_path, 'string' => $f->fake_full_path,
'relatives' => array ($f->mask) 'relatives' => array ($f->mask)
) )) as $entry)
);
while (list ($num, $entry) = each ($ls))
{ {
if ($entry['mime_type'] == 'Directory') if ($entry['mime_type'] == 'Directory')
{ {
@ -1521,7 +1512,7 @@
) )
{ {
/* We got $ls from above, before we renamed the directory */ /* We got $ls from above, before we renamed the directory */
while (list ($num, $entry) = each ($ls)) foreach ($ls as $entry)
{ {
$newdir = ereg_replace ("^$f->fake_full_path", $t->fake_full_path, $entry['directory']); $newdir = ereg_replace ("^$f->fake_full_path", $t->fake_full_path, $entry['directory']);
$newdir_clean = $this->clean_string (array ('string' => $newdir)); $newdir_clean = $this->clean_string (array ('string' => $newdir));
@ -1647,7 +1638,7 @@
); );
/* First, we cycle through the entries and delete the files */ /* First, we cycle through the entries and delete the files */
while (list ($num, $entry) = each ($ls)) foreach($ls as $entry)
{ {
if ($entry['mime_type'] == 'Directory') if ($entry['mime_type'] == 'Directory')
{ {
@ -1662,8 +1653,7 @@
} }
/* Now we cycle through again and delete the directories */ /* Now we cycle through again and delete the directories */
reset ($ls); foreach ($ls as $entry)
while (list ($num, $entry) = each ($ls))
{ {
if ($entry['mime_type'] != 'Directory') if ($entry['mime_type'] != 'Directory')
{ {
@ -1769,7 +1759,18 @@
if ($this->file_actions) if ($this->file_actions)
{ {
if (!@mkdir ($p->real_full_path, 0770)) if (!@is_dir($p->real_leading_dirs_clean)) // eg. /home or /group does not exist
{
if (!@mkdir($p->real_leading_dirs_clean,0770)) // ==> create it
{
return False;
}
}
if (@is_dir($p->real_full_path)) // directory already exists
{
$this->update_real($data,True); // update its contents
}
elseif (!@mkdir ($p->real_full_path, 0770))
{ {
return False; return False;
} }
@ -1969,13 +1970,10 @@
$change_attributes = 0; $change_attributes = 0;
reset ($this->attributes); foreach ($this->attributes as $attribute)
while (list ($num, $attribute) = each ($this->attributes))
{ {
if (isset ($data['attributes'][$attribute])) if (isset ($data['attributes'][$attribute]))
{ {
$$attribute = $data['attributes'][$attribute];
/* /*
Indicate that the EDITED_COMMENT operation needs to be journaled, Indicate that the EDITED_COMMENT operation needs to be journaled,
but only if the comment changed but only if the comment changed
@ -1985,22 +1983,23 @@
$edited_comment = 1; $edited_comment = 1;
} }
$$attribute = $this->clean_string (array ('string' => $$attribute));
if ($change_attributes > 0) if ($change_attributes > 0)
{ {
$sql .= ', '; $sql .= ', ';
} }
$sql .= "$attribute='" . $$attribute . "'"; $sql .= "$attribute='" . $this->clean_string (array ('string' => $data['attributes'][$attribute])) . "'";
$change_attributes++; $change_attributes++;
} }
} }
if (!$change_attributes)
{
return True; // nothing to do
}
$sql .= " WHERE file_id='$record[file_id]'"; $sql .= " WHERE file_id='$record[file_id]'";
$sql .= $this->extra_sql (array ('query_type' => VFS_SQL_UPDATE)); $sql .= $this->extra_sql (array ('query_type' => VFS_SQL_UPDATE));
$query = $GLOBALS['phpgw']->db->query ($sql, __LINE__, __FILE__); $query = $GLOBALS['phpgw']->db->query ($sql, __LINE__, __FILE__);
if ($query) if ($query)
@ -2241,15 +2240,12 @@
return $size; return $size;
} }
$ls_array = $this->ls (array( foreach($this->ls (array(
'string' => $p->fake_full_path, 'string' => $p->fake_full_path,
'relatives' => array ($p->mask), 'relatives' => array ($p->mask),
'checksubdirs' => $data['checksubdirs'], 'checksubdirs' => $data['checksubdirs'],
'nofiles' => !$data['checksubdirs'] 'nofiles' => !$data['checksubdirs']
) )) as $file_array)
);
while (list ($num, $file_array) = each ($ls_array))
{ {
/* /*
Make sure the file is in the directory we want, and not Make sure the file is in the directory we want, and not
@ -2357,8 +2353,7 @@
/* SELECT all, the, attributes */ /* SELECT all, the, attributes */
$sql = 'SELECT '; $sql = 'SELECT ';
reset ($this->attributes); foreach ($this->attributes as $num => $attribute)
while (list ($num, $attribute) = each ($this->attributes))
{ {
if ($num) if ($num)
{ {
@ -2377,8 +2372,7 @@
/* We return an array of one array to maintain the standard */ /* We return an array of one array to maintain the standard */
$rarray = array (); $rarray = array ();
reset ($this->attributes); foreach($this->attributes as $attribute)
while (list ($num, $attribute) = each ($this->attributes))
{ {
if ($attribute == 'mime_type' && !$record[$attribute]) if ($attribute == 'mime_type' && !$record[$attribute])
{ {
@ -2442,8 +2436,7 @@
/* SELECT all, the, attributes FROM phpgw_vfs WHERE file=$dir */ /* SELECT all, the, attributes FROM phpgw_vfs WHERE file=$dir */
$sql = 'SELECT '; $sql = 'SELECT ';
reset ($this->attributes); foreach($this->attributes as $num => $attribute)
while (list ($num, $attribute) = each ($this->attributes))
{ {
if ($num) if ($num)
{ {
@ -2483,8 +2476,7 @@
continue; continue;
} }
reset ($this->attributes); foreach($this->attributes as $attribute)
while (list ($num, $attribute) = each ($this->attributes))
{ {
if ($attribute == 'mime_type' && !$record[$attribute]) if ($attribute == 'mime_type' && !$record[$attribute])
{ {
@ -2510,7 +2502,7 @@
/* /*
* See vfs_shared * See vfs_shared
*/ */
function update_real ($data) function update_real ($data,$recursive = False)
{ {
if (!is_array ($data)) if (!is_array ($data))
{ {
@ -2563,7 +2555,7 @@
$rarray = array (); $rarray = array ();
} }
while (list ($num, $file_array) = each ($rarray)) foreach($rarray as $num => $file_array)
{ {
$p2 = $this->path_parts (array( $p2 = $this->path_parts (array(
'string' => $file_array['directory'] . '/' . $file_array['name'], 'string' => $file_array['directory'] . '/' . $file_array['name'],
@ -2588,22 +2580,18 @@
'relatives' => array (RELATIVE_NONE) 'relatives' => array (RELATIVE_NONE)
) )
); );
$this->set_attributes (array(
'string' => $p2->fake_full_path,
'relatives' => array (RELATIVE_NONE),
'attributes' => $set_attributes_array
)
);
} }
else $this->set_attributes (array(
'string' => $p2->fake_full_path,
'relatives' => array (RELATIVE_NONE),
'attributes' => $set_attributes_array
)
);
if ($recursive && $file_array['mime_type'] == 'Directory')
{ {
$this->set_attributes (array( $dir_data = $data;
'string' => $p2->fake_full_path, $dir_data['string'] = $file_array['directory'] . '/' . $file_array['name'];
'relatives' => array (RELATIVE_NONE), $this->update_real($dir_data,$recursive);
'attributes' => $set_attributes_array
)
);
} }
} }
} }