Bug 821168 - Use hardlinks for backing up pre-update files. r=eshan

This commit is contained in:
Dave Hylands 2013-01-03 16:53:33 -08:00
parent 3a7ce5f7bd
commit e293cbbd78

View File

@ -82,6 +82,11 @@ void LaunchMacPostProcess(const char* aAppExe);
#if defined(MOZ_WIDGET_GONK)
# include "automounter_gonk.h"
# include <unistd.h>
# define MAYBE_USE_HARD_LINKS 1
static bool sUseHardLinks = true;
#else
# define MAYBE_USE_HARD_LINKS 0
#endif
#ifdef XP_WIN
@ -603,6 +608,25 @@ static int ensure_copy_symlink(const NS_tchar *path, const NS_tchar *dest)
}
#endif
#if MAYBE_USE_HARD_LINKS
/*
* Creates a hardlink (destFilename) which points to the existing file
* (srcFilename).
*
* @return 0 if successful, an error otherwise
*/
static int
create_hard_link(const NS_tchar *srcFilename, const NS_tchar *destFilename)
{
if (link(srcFilename, destFilename) < 0) {
LOG(("link(%s, %s) failed errno = %d", srcFilename, destFilename, errno));
return WRITE_ERROR;
}
return OK;
}
#endif
// Copy the file named path onto a new file named dest.
static int ensure_copy(const NS_tchar *path, const NS_tchar *dest)
{
@ -630,6 +654,16 @@ static int ensure_copy(const NS_tchar *path, const NS_tchar *dest)
}
#endif
#if MAYBE_USE_HARD_LINKS
if (sUseHardLinks) {
if (!create_hard_link(path, dest)) {
return OK;
}
// Since we failed to create the hard link, fall through and copy the file.
sUseHardLinks = false;
}
#endif
AutoFile infile = ensure_open(path, NS_T("rb"), ss.st_mode);
if (!infile) {
LOG(("ensure_copy: failed to open the file for reading: " LOG_S ", err: %d",