- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有以下代码,每两次执行一次全天分钟:
int sucessfully_deleted = DeleteFile(dest_filename);
if (!sucessfully_deleted)
{
// this never happens
}
rename(source_filename,dest_filename);
每隔几个小时,rename() 就会失败一次,errno=13 (EACCES)。涉及的文件都位于 DropBox 目录中,我有一种预感,DropBox 可能是原因。我认为 DeleteFile() 函数可能会返回一个非零的 successfully_deleted ,但实际上 DropBox 可能仍然忙于做一些与删除相关的事情,从而阻止 rename() 成功。我接下来要做的是将 rename() 更改为 my_rename() ,这将尝试 rename() 并且在任何失败时都会 Sleep() 一秒钟并尝试第二次。果然从那以后就一直运行良好。此外,我每隔几个小时就会收到一条显示首次尝试失败的诊断消息。第二次尝试从未失败。
所以你可以说问题已经完全解决了......但我想了解可能发生的事情,以便在未来更好地保护自己免受任何相关的 DropBox 问题......
真的,我想要一个新的 super_delete() 函数,该函数在文件被正确删除并在所有方面完成之前不会返回。
最佳答案
在windows下要求删除文件真的从不删除文件而已。它用特殊标志 (FCB_STATE_DELETE_ON_CLOSE
) 标记它 FCB(文件控制 block )。真正的删除只有在最后一个文件句柄关闭时才会发生。
The
DeleteFile
function marks a file for deletion on close. Therefore, the file deletion does not occur until the last handle to the file is closed. Subsequent calls toCreateFile
to open the file fail withERROR_ACCESS_DENIED
.
如果存在部分(内存映射文件)在文件上打开 - 文件甚至不能被标记为删除。 api 调用失败,返回 STATUS_CANNOT_DELETE
。所以一般不可能总是删除文件。
如果存在另一个打开的文件句柄(但不是部分!),从 Windows 10 rs1 开始存在新的删除功能 - FileDispositionInformationEx
与 FILE_DISPOSITION_POSIX_SEMANTICS
.在这种情况下:
Normally a file marked for deletion is not actually deleted until all open handles for the file have been closed and the link count for the file is zero. When marking a file for deletion using FILE_DISPOSITION_POSIX_SEMANTICS, the link gets removed from the visible namespace as soon as the POSIX delete handle has been closed, but the file’s data streams remain accessible by other existing handles until the last handle has been closed.
ULONG DeletePosix(PCWSTR lpFileName)
{
HANDLE hFile = CreateFileW(lpFileName, DELETE, FILE_SHARE_VALID_FLAGS, 0, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_OPEN_REPARSE_POINT, 0);
if (hFile == INVALID_HANDLE_VALUE)
{
return GetLastError();
}
static FILE_DISPOSITION_INFO_EX fdi = { FILE_DISPOSITION_DELETE| FILE_DISPOSITION_POSIX_SEMANTICS };
ULONG dwError = SetFileInformationByHandle(hFile, FileDispositionInfoEx, &fdi, sizeof(fdi))
? NOERROR : GetLastError();
// win10 rs1: file removed from parent folder here
CloseHandle(hFile);
return dwError;
}
关于c++ - DropBox 会干扰 DeleteFile()/rename(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52687370/
这是我的 + 部分: function insert(){ var linkElement = document.getElementById("BackButton"); var linkEl
我有两辆 buggy 在轨道上移动,它们都使用超声波测量模块来检测路径中的障碍物,并由 Arduino 微 Controller 控制。两个超声波传感器以相同的频率工作,并且这个频率不能改变。两个超声
希望能快速解决这个问题。我有一个用文件位置替换特定值的脚本。不幸的是,该位置似乎经常包含\n 或 n\(因为当前目录位于临时文件夹中),导致该行中断或从该行中完全删除自身,从而使文件夹位置无效。 临时
我使用的是 Mac OSX 10.10.1。我通常使用brew或pip来安装所有东西。我注意到我的 virtualenv 总是抓取我本地安装的所有 Python 包。我通过删除我的 $PYTHONPA
我正在尝试使用 str_replace 将两个字母的语言缩写转换为完整的单词。我遇到的问题是它们在回显时会相互影响。 $lang = str_replace("en", "English", $lan
我已经创建了用于结束通话的 aidl 文件 ITelephony.aidl。现在,在通话结束之前,我需要生成正在进行的通话中的语音,以便听众认为接下来的工作有问题。我尝试通过三种方式自己解决这个问题:
使用这个查询,我得到了我需要的每个客户下的订单数量的结果。但是,当我在 SELECT 字段中使用 SUM(OrderLine.ActualPrice) 并使用内部联接将 Order 表链接到包含价格的
在 Spring Boot 应用程序中,仅使用注释,我想实现安全性 我已将 @EnableGlobalMethodSecurity(jsr360Enabled=true) 添加到配置类。该类还有一个
我一直在 Linux 下开发一个多线程程序,对信号处理有特殊要求。例如,我需要程序打印单个 Ctrl-C 输入的统计信息。 我使用 pthread_sigmask 和 sigwait 实现了这一点,即
作为我第一次涉足 Dynamic Scala 领域,我想我会尝试通过 applyDynamic 访问 bean 属性。 我的第一个非常粗略的剪裁是 trait BeanProperties ext
我知道这是一个令人沮丧的话题,但我尝试遵循文档和其他类似的帖子。 我的问题是,除非重新加载页面,否则 JS 将无法工作。 我有以下 JS: $(function() { $('a.form-sho
我正在使用 JQuery Ajax 从服务器获取脚本。 $.ajax({ url: src, type: "GET", dataType: "script", time
我正在尝试根据每个产品的选定数量分别输出计算价格。我尝试复制代码并重命名所有变量,但输出是由各种增加/减少按钮触发的。 这是目前的代码: $(".incr-btn_mobile").on("click
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: jQuery in Greasemonkey 1.0 conflicts with websites usi
我在一个 iOS 应用程序 (Obj-C) 中有一个 View ,它在中心有一个 ImageView ,紧接着在其下方有一个 slider 。 ImageView 显示专辑封面, slider 可用于
我有一个 View Controller ,将 UITapGestureRecognizer 附加到它的主 UIView,并使用户能够点击屏幕以使状态、导航和工具栏重新出现/消失(如照片应用程序)。我
我正在尝试在我的应用程序中设置 log4j,但我的一个第三方 JAR 似乎以某种方式不断将我的日志级别设置为“关闭”。它仅在执行该库中的代码时发生。我不知道它是如何做到这一点的,因为我没有使用它知道名
我有一个 UIScrollView,其框架与包含的 View Controller 相同。 当 ScrollView 的缩放比例大于 1 时,从屏幕左侧 50% 开始从左向右滑动会导致 interac
我是网页设计的新手,最近接触了 Bootstrap。我最近也开始使用 Codepen。在 Codepen 中完成一个元素后,我将代码从那里复制并粘贴到 Sublime 中,无论出于何种原因,它更改了我
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and t
我是一名优秀的程序员,十分优秀!