Don’t remove existing mate on install

The reason for this is that we might be able to overwrite mate even if we do not have write access to the parent directory. This will avoid us having to prompt the user for an admin password (when updating mate).

It should be mentioned though that incase mate is not a regular file, we do need to remove it first, because if e.g. it is a symbolic link, our install would write to where the link points to.
This commit is contained in:
Allan Odgaard
2012-08-21 21:32:40 +02:00
parent 53bcc664b3
commit 0d4185bfeb

View File

@@ -110,7 +110,7 @@ static bool rm_path (std::string const& path, AuthorizationRef& auth)
static bool cp_path (std::string const& src, std::string const& dst, AuthorizationRef& auth)
{
if(access(path::parent(dst).c_str(), W_OK) == 0)
if(access(dst.c_str(), W_OK) == 0 || access(dst.c_str(), X_OK) != 0 && access(path::parent(dst).c_str(), W_OK) == 0)
{
if(copyfile(src.c_str(), dst.c_str(), NULL, COPYFILE_ALL | COPYFILE_NOFOLLOW_SRC) == 0)
return true;
@@ -131,7 +131,7 @@ static bool install_mate (std::string const& src, std::string const& dst)
if(mk_dir(path::parent(dst), auth))
{
struct stat buf;
if(lstat(dst.c_str(), &buf) == 0 && !rm_path(dst, auth))
if(lstat(dst.c_str(), &buf) == 0 && !S_ISREG(buf.st_mode) && !rm_path(dst, auth))
return false;
return cp_path(src, dst, auth);
}