Quantcast
Channel: The Old New Thing
Viewing all articles
Browse latest Browse all 24428

re: You already know the answer since you do it yourself

$
0
0

@Ben: "So you can detect when the user replaces your clipboard content with a new cut/copy, and then you can delete the temporary files.

Some applications also call EmptyClipboard if they still have data on the clipboard when they exit, allowing the files to go away also."

No.  Here's why:

1.  Copy some big data to temporary files / clipboard using your app.

2.  User pastes your files into Windows Explorer.

3.  Windows Explorer kicks off a background thread to do the asynchronous file copy.

4.  Now the user copies something else.

5.  As you propose, your app tries to delete temporary files, thinking that the user has copied something else and that the files aren't needed.  But the files are still in use.

6.  Your app might fail, since Windows Explorer would have a file open and locked so it can be copied.

7.  Windows Explorer would fail, since you probably successfully deleted some files that it had enumerated for copying.

For smaller files, the file paste might be fast enough that the user couldn't copy something else fast enough.  So you might get away with it most of the time.  But it's still a race condition.


Viewing all articles
Browse latest Browse all 24428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>