c++ - How to check if file is already opened using boost -
how check if file opened using boost if file not opened removed file other wise nothing
boost::filesystem::wpath file("c://test.txt"); if(boost::filesystem::exists(file)) { if(here want check file open or not, if open run else) { boost::filesystem::remove(file); } else { } }
it's job of os prevent/allow this.
each os has it's own ways of locking exclusive use, in case deletion fail anyways.
other oses (posix) unlink file entry inode, , file keeps remaining accessible processes have file opened. when last use of inode goes away, file deleted.
in short, don't try detect front, see whether deletion failed. otherwise you'll run race condition mentioned
how going deal situations, file opened in between check , attempt remove it? here
it seems have missed point of (seeing reply), , mike explained
Comments
Post a Comment