⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 io.c

📁 subversion-1.4.3-1.tar.gz 配置svn的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
  const char *path_apr;  apr_finfo_t finfo;  apr_fileperms_t perms_to_set;  SVN_ERR(svn_path_cstring_from_utf8(&path_apr, path, pool));  /* Try to change only a minimal amount of the perms first      by getting the current perms and adding bits     only on where read perms are granted.  If this fails     fall through to just setting file attributes. */  status = apr_stat(&finfo, path_apr, APR_FINFO_PROT, pool);  if (status)    {      if (ignore_enoent && APR_STATUS_IS_ENOENT(status))        return SVN_NO_ERROR;      else if (status != APR_ENOTIMPL)        return svn_error_wrap_apr(status,                                  _("Can't change perms of file '%s'"),                                  svn_path_local_style(path, pool));      return SVN_NO_ERROR;    }  perms_to_set = finfo.protection;  if (change_readwrite)    {      if (enable_write) /* Make read-write. */        SVN_ERR(get_default_file_perms(path, &perms_to_set, pool));      else        {          if (finfo.protection & APR_UREAD)            perms_to_set &= ~APR_UWRITE;          if (finfo.protection & APR_GREAD)            perms_to_set &= ~APR_GWRITE;          if (finfo.protection & APR_WREAD)            perms_to_set &= ~APR_WWRITE;        }    }  if (change_executable)    {      if (executable)        {          if (finfo.protection & APR_UREAD)            perms_to_set |= APR_UEXECUTE;          if (finfo.protection & APR_GREAD)            perms_to_set |= APR_GEXECUTE;          if (finfo.protection & APR_WREAD)            perms_to_set |= APR_WEXECUTE;        }      else        {          if (finfo.protection & APR_UREAD)            perms_to_set &= ~APR_UEXECUTE;          if (finfo.protection & APR_GREAD)            perms_to_set &= ~APR_GEXECUTE;          if (finfo.protection & APR_WREAD)            perms_to_set &= ~APR_WEXECUTE;        }    }  /* If we aren't changing anything then just return, this saves     some system calls and helps with shared working copies */  if (perms_to_set == finfo.protection)    return SVN_NO_ERROR;  status = apr_file_perms_set(path_apr, perms_to_set);  if (!status)    return SVN_NO_ERROR;  if (APR_STATUS_IS_EPERM(status))    {      /* We don't have permissions to change the         permissions!  Try a move, copy, and delete         workaround to see if we can get the file owned by         us.  If these succeed, try the permissions set         again.         Note that we only attempt this in the         stat-available path.  This assumes that the         move-copy workaround will only be helpful on         platforms that implement apr_stat. */      SVN_ERR(reown_file(path_apr, pool));      status = apr_file_perms_set(path_apr, perms_to_set);    }  if (!status)    return SVN_NO_ERROR;  if (ignore_enoent && APR_STATUS_IS_ENOENT(status))    return SVN_NO_ERROR;  else if (status == APR_ENOTIMPL)    {      /* At least try to set the attributes. */      apr_fileattrs_t attrs = 0;      apr_fileattrs_t attrs_values = 0;      if (change_readwrite)        {          attrs = APR_FILE_ATTR_READONLY;          if (!enable_write)            attrs_values = APR_FILE_ATTR_READONLY;        }      if (change_executable)        {          attrs = APR_FILE_ATTR_EXECUTABLE;          if (executable)            attrs_values = APR_FILE_ATTR_EXECUTABLE;        }      status = apr_file_attrs_set(path_apr, attrs, attrs_values, pool);    }  return svn_error_wrap_apr(status,                            _("Can't change perms of file '%s'"),                            svn_path_local_style(path, pool));}#endifsvn_error_t *svn_io_set_file_read_write_carefully(const char *path,                                     svn_boolean_t enable_write,                                     svn_boolean_t ignore_enoent,                                     apr_pool_t *pool){  if (enable_write)    return svn_io_set_file_read_write(path, ignore_enoent, pool);  return svn_io_set_file_read_only(path, ignore_enoent, pool);}svn_error_t *svn_io_set_file_read_only(const char *path,                          svn_boolean_t ignore_enoent,                          apr_pool_t *pool){  /* On Windows, just set the file attributes -- on unix call     our internal function which attempts to honor the umask. */#ifndef WIN32  return io_set_file_perms(path, TRUE, FALSE, FALSE, FALSE,                           ignore_enoent, pool);#else  apr_status_t status;  const char *path_apr;  SVN_ERR(svn_path_cstring_from_utf8(&path_apr, path, pool));  status = apr_file_attrs_set(path_apr,                              APR_FILE_ATTR_READONLY,                              APR_FILE_ATTR_READONLY,                              pool);  if (status && status != APR_ENOTIMPL)    if (!ignore_enoent || !APR_STATUS_IS_ENOENT(status))      return svn_error_wrap_apr(status,                                _("Can't set file '%s' read-only"),                                svn_path_local_style(path, pool));  return SVN_NO_ERROR;#endif}svn_error_t *svn_io_set_file_read_write(const char *path,                           svn_boolean_t ignore_enoent,                           apr_pool_t *pool){  /* On Windows, just set the file attributes -- on unix call     our internal function which attempts to honor the umask. */#ifndef WIN32  return io_set_file_perms(path, TRUE, TRUE, FALSE, FALSE,                           ignore_enoent, pool);#else  apr_status_t status;  const char *path_apr;  SVN_ERR(svn_path_cstring_from_utf8(&path_apr, path, pool));  status = apr_file_attrs_set(path_apr,                              0,                              APR_FILE_ATTR_READONLY,                              pool);  if (status && status != APR_ENOTIMPL)    if (!ignore_enoent || !APR_STATUS_IS_ENOENT(status))      return svn_error_wrap_apr(status,                                _("Can't set file '%s' read-write"),                                svn_path_local_style(path, pool));  return SVN_NO_ERROR;#endif}svn_error_t *svn_io_set_file_executable(const char *path,                           svn_boolean_t executable,                           svn_boolean_t ignore_enoent,                           apr_pool_t *pool){  /* On Windows, just exit -- on unix call our internal function  which attempts to honor the umask. */#ifndef WIN32  return io_set_file_perms(path, FALSE, FALSE, TRUE, executable,                           ignore_enoent, pool);#else  return SVN_NO_ERROR;#endif}svn_error_t *svn_io_is_file_executable(svn_boolean_t *executable,                           const char *path,                           apr_pool_t *pool){#if defined(APR_HAS_USER) && !defined(WIN32)  apr_finfo_t file_info;  apr_status_t apr_err;  apr_uid_t uid;  apr_gid_t gid;  *executable = FALSE;    /* Get file and user info. */  SVN_ERR(svn_io_stat(&file_info, path,                       (APR_FINFO_PROT | APR_FINFO_OWNER),                       pool));  apr_err = apr_uid_current(&uid, &gid, pool);  if (apr_err)    return svn_error_wrap_apr(apr_err, _("Error getting UID of process"));      /* Check executable bit for current user. */  if (apr_uid_compare(uid, file_info.user) == APR_SUCCESS)    *executable = (file_info.protection & APR_UEXECUTE);  else if (apr_gid_compare(gid, file_info.group) == APR_SUCCESS)    *executable = (file_info.protection & APR_GEXECUTE);  else    *executable = (file_info.protection & APR_WEXECUTE);#else  /* defined(WIN32) || !defined(APR_HAS_USER) */  *executable = FALSE;#endif  return SVN_NO_ERROR;}/*** File locking. ***//* Clear all outstanding locks on ARG, an open apr_file_t *. */static apr_status_tsvn_io__file_clear_and_close(void *arg){  apr_status_t apr_err;  apr_file_t *f = arg;  /* Remove locks. */  apr_err = apr_file_unlock(f);  if (apr_err)    return apr_err;  /* Close the file. */  apr_err = apr_file_close(f);  if (apr_err)    return apr_err;  return 0;}svn_error_t *svn_io_file_lock(const char *lock_file,                              svn_boolean_t exclusive,                              apr_pool_t *pool){  return svn_io_file_lock2(lock_file, exclusive, FALSE, pool);}svn_error_t *svn_io_file_lock2(const char *lock_file,                               svn_boolean_t exclusive,                               svn_boolean_t nonblocking,                               apr_pool_t *pool){  int locktype = APR_FLOCK_SHARED;  apr_file_t *lockfile_handle;  apr_int32_t flags;  apr_status_t apr_err;  if(exclusive == TRUE)    locktype = APR_FLOCK_EXCLUSIVE;  flags = APR_READ;  if (locktype == APR_FLOCK_EXCLUSIVE)    flags |= APR_WRITE;  if (nonblocking == TRUE)    locktype |= APR_FLOCK_NONBLOCK;  SVN_ERR(svn_io_file_open(&lockfile_handle, lock_file, flags,                           APR_OS_DEFAULT,                           pool));  /* Get lock on the filehandle. */  apr_err = apr_file_lock(lockfile_handle, locktype);  if (apr_err)    {      switch (locktype & APR_FLOCK_TYPEMASK)        {        case APR_FLOCK_SHARED:          return svn_error_wrap_apr            (apr_err, _("Can't get shared lock on file '%s'"),             svn_path_local_style(lock_file, pool));        case APR_FLOCK_EXCLUSIVE:          return svn_error_wrap_apr            (apr_err, _("Can't get exclusive lock on file '%s'"),             svn_path_local_style(lock_file, pool));        default:          /* Cannot happen. */          abort();        }    }    apr_pool_cleanup_register(pool, lockfile_handle,                             svn_io__file_clear_and_close,                            apr_pool_cleanup_null);                               return SVN_NO_ERROR;}/* Data consistency/coherency operations. */static svn_error_t *do_io_file_wrapper_cleanup(apr_file_t *file, apr_status_t status,                            const char *msg, const char *msg_no_name,                           apr_pool_t *pool);svn_error_t *svn_io_file_flush_to_disk(apr_file_t *file,                                       apr_pool_t *pool){  apr_os_file_t filehand;  /* First make sure that any user-space buffered data is flushed. */  SVN_ERR(do_io_file_wrapper_cleanup(file, apr_file_flush(file),                                     N_("Can't flush file '%s'"),                                     N_("Can't flush stream"),                                     pool));  apr_os_file_get(&filehand, file);      /* Call the operating system specific function to actually force the     data to disk. */  {#ifdef WIN32          if (! FlushFileBuffers(filehand))        return svn_error_wrap_apr          (apr_get_os_error(), _("Can't flush file to disk"));      #else      int rv;      do {        rv = fsync(filehand);      } while (rv == -1 && APR_STATUS_IS_EINTR(apr_get_os_error()));      /* If the file is in a memory filesystem, fsync() may return         EINVAL.  Presumably the user knows the risks, and we can just         ignore the error. */      if (rv == -1 && APR_STATUS_IS_EINVAL(apr_get_os_error()))        return SVN_NO_ERROR;      if (rv == -1)        return svn_error_wrap_apr          (apr_get_os_error(), _("Can't flush file to disk"));#endif  }  return SVN_NO_ERROR;}    /* TODO write test for these two functions, then refactor. */svn_error_t *svn_stringbuf_from_file(svn_stringbuf_t **result,                        const char *filename,                        apr_pool_t *pool){  apr_file_t *f = NULL;  if (filename[0] == '-' && filename[1] == '\0')    return svn_error_create        (SVN_ERR_UNSUPPORTED_FEATURE, NULL,         _("Reading from stdin is currently broken, so disabled"));  SVN_ERR(svn_io_file_open(&f, filename, APR_READ, APR_OS_DEFAULT, pool));  SVN_ERR(svn_stringbuf_from_aprfile(result, f, pool));  SVN_ERR(svn_io_file_close(f, pool));  return SVN_NO_ERROR;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -