Skip to content
Snippets Groups Projects
Commit d3b96b15cf6e authored by Lasse Collin's avatar Lasse Collin
Browse files

xz: Always close the file before trying to delete it.

unlink() can return EBUSY in errno for open files on some
operating systems and file systems.
parent ba3da99d5623
No related branches found
No related tags found
No related merge requests found
......@@ -675,5 +675,16 @@
#endif
if (pair->src_fd != STDIN_FILENO && pair->src_fd != -1) {
#ifdef TUKLIB_DOSLIKE
// Close the file before possibly unlinking it. On DOS-like
// systems this is always required since unlinking will fail
// if the file is open. On POSIX systems it usually works
// to unlink open files, but in some cases it doesn't and
// one gets EBUSY in errno.
//
// xz 5.2.2 and older unlinked the file before closing it
// (except on DOS-like systems). The old code didn't handle
// EBUSY and could fail e.g. on some CIFS shares. The
// advantage of unlinking before closing is negligible
// (avoids a race between close() and stat()/lstat() and
// unlink()), so let's keep this simple.
(void)close(pair->src_fd);
......@@ -679,3 +690,2 @@
(void)close(pair->src_fd);
#endif
......@@ -681,10 +691,3 @@
// If we are going to unlink(), do it before closing the file.
// This way there's no risk that someone replaces the file and
// happens to get same inode number, which would make us
// unlink() wrong file.
//
// NOTE: DOS-like systems are an exception to this, because
// they don't allow unlinking files that are open. *sigh*
if (success && !opt_keep_original)
io_unlink(pair->src_name, &pair->src_st);
......@@ -689,9 +692,5 @@
if (success && !opt_keep_original)
io_unlink(pair->src_name, &pair->src_st);
#ifndef TUKLIB_DOSLIKE
(void)close(pair->src_fd);
#endif
}
return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment