简体   繁体   English

Boost:copy_file失败,访问被拒绝,但是没有权限问题

[英]Boost: copy_file fail with access denied but there are no permission problem

I wrote the following routine in order to copy all files in a directory to a subdirectory and then remove them, but I keep getting an access denied on the copy_fail which looks misleading to me. 我编写了以下例程,以便将目录中的所有文件复制到子目录中,然后将其删除,但是我不断获得对copy_fail的拒绝访问,这似乎在误导我。 Paths are corrects, files exist and permission are not read-only in the destination directory just created. 在刚刚创建的目标目录中,路径正确,文件存在且权限不是只读的。

Any suggestion how to hunt the source of the problem? 有什么建议如何寻找问题的根源吗?

I tried to debug, but I don't have the boost::filesystem source code. 我尝试调试,但是没有boost :: filesystem源代码。

Any suggestion is appreciated. 任何建议表示赞赏。

void
moveConfigurationFileToSubDirectory()
{
 // TODO: Catch errors.

 boost::filesystem::path full_path( boost::filesystem::current_path() );

 // Create directory subdir if not exist
 boost::filesystem::path subdirPath(kSubdirectory);
    if ( !boost::filesystem::exists(subdirPath) )
 {
  PLog::DEV.Development(devVerbose, "%s: creating directory %s", __FUNCTION__, subdirPath.string());
  boost::filesystem::create_directories(subdirPath);
 } else
  PLog::DEV.Development(devVerbose, "%s: directory %s exist", __FUNCTION__, subdirPath.string());

 // Iterate through the configuration files defined in the static array
 // copy all files with overwrite flag, if successfully delete file (looks like there is not remove)
 for (int i = 0; i < kNumberOfConfigurationFiles; i++)
 {
  boost::filesystem::path currentConfigurationFile(kConfigurationFiles[i]);

  try
  {
   boost::filesystem::copy_file(currentConfigurationFile, subdirPath, boost::filesystem::copy_option::overwrite_if_exists);
   boost::filesystem::remove(currentConfigurationFile);
  }
  catch (exception& e)
  {
   PLog::DEV.Development(devError, "%s: exception - %s", __FUNCTION__, e.what());
  }
 }
}

You have to specify the filename you want for subdirPath and not just the path. 您必须为subdirPath指定所需的文件名,而不仅仅是路径。 boost's copy_file isn't smart enough to know that by specifying a directory name, you want the file to have the same name as the source. boost的copy_file不够聪明,无法知道通过指定目录名称来使文件与源具有相同的名称。

What OS are running this on? 在什么操作系统上运行它? If on Linux/Unix then have you considered permissions on directory holding your source files (you are removing currentConfigurationFile, this means that directory holding that file must have write permission)? 如果在Linux / Unix上,您是否考虑过保存源文件的目录的权限(要删除currentConfigurationFile,这意味着保存该文件的目录必须具有写权限)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM