Commit 89472db9 authored by Alexandre Julliard's avatar Alexandre Julliard

msi: Create temp files in the destination directory instead of the root.

parent 9059fee7
......@@ -195,23 +195,25 @@ static UINT copy_install_file(MSIPACKAGE *package, MSIFILE *file, LPWSTR source)
}
if (gle == ERROR_SHARING_VIOLATION || gle == ERROR_USER_MAPPED_FILE)
{
WCHAR tmpfileW[MAX_PATH], *pathW, *p;
WCHAR *tmpfileW, *pathW, *p;
DWORD len;
TRACE("file in use, scheduling rename operation\n");
GetTempFileNameW(szBackSlash, szMsi, 0, tmpfileW);
len = strlenW(file->TargetPath) + strlenW(tmpfileW) + 1;
if (!(pathW = msi_alloc(len * sizeof(WCHAR))))
return ERROR_OUTOFMEMORY;
strcpyW(pathW, file->TargetPath);
if (!(pathW = strdupW( file->TargetPath ))) return ERROR_OUTOFMEMORY;
if ((p = strrchrW(pathW, '\\'))) *p = 0;
strcatW(pathW, tmpfileW);
len = strlenW( pathW ) + 16;
if (!(tmpfileW = msi_alloc(len * sizeof(WCHAR))))
{
msi_free( pathW );
return ERROR_OUTOFMEMORY;
}
if (!GetTempFileNameW( pathW, szMsi, 0, tmpfileW )) tmpfileW[0] = 0;
msi_free( pathW );
if (CopyFileW(source, pathW, FALSE) &&
if (CopyFileW(source, tmpfileW, FALSE) &&
MoveFileExW(file->TargetPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT) &&
MoveFileExW(pathW, file->TargetPath, MOVEFILE_DELAY_UNTIL_REBOOT))
MoveFileExW(tmpfileW, file->TargetPath, MOVEFILE_DELAY_UNTIL_REBOOT))
{
file->state = msifs_installed;
package->need_reboot = 1;
......@@ -221,8 +223,9 @@ static UINT copy_install_file(MSIPACKAGE *package, MSIFILE *file, LPWSTR source)
{
gle = GetLastError();
WARN("failed to schedule rename operation: %d)\n", gle);
DeleteFileW( tmpfileW );
}
msi_free(pathW);
msi_free(tmpfileW);
}
return gle;
......
......@@ -458,32 +458,36 @@ static INT_PTR cabinet_copy_file(FDINOTIFICATIONTYPE fdint,
}
if (err == ERROR_SHARING_VIOLATION || err == ERROR_USER_MAPPED_FILE)
{
WCHAR tmpfileW[MAX_PATH], *tmppathW, *p;
WCHAR *tmpfileW, *tmppathW, *p;
DWORD len;
TRACE("file in use, scheduling rename operation\n");
GetTempFileNameW(szBackSlash, szMsi, 0, tmpfileW);
len = strlenW(path) + strlenW(tmpfileW) + 1;
if (!(tmppathW = msi_alloc(len * sizeof(WCHAR))))
return ERROR_OUTOFMEMORY;
strcpyW(tmppathW, path);
if (!(tmppathW = strdupW( path ))) return ERROR_OUTOFMEMORY;
if ((p = strrchrW(tmppathW, '\\'))) *p = 0;
strcatW(tmppathW, tmpfileW);
len = strlenW( tmppathW ) + 16;
if (!(tmpfileW = msi_alloc(len * sizeof(WCHAR))))
{
msi_free( tmppathW );
return ERROR_OUTOFMEMORY;
}
if (!GetTempFileNameW(tmppathW, szMsi, 0, tmpfileW)) tmpfileW[0] = 0;
msi_free( tmppathW );
handle = CreateFileW(tmppathW, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, attrs, NULL);
handle = CreateFileW(tmpfileW, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, attrs, NULL);
if (handle != INVALID_HANDLE_VALUE &&
MoveFileExW(path, NULL, MOVEFILE_DELAY_UNTIL_REBOOT) &&
MoveFileExW(tmppathW, path, MOVEFILE_DELAY_UNTIL_REBOOT))
MoveFileExW(tmpfileW, path, MOVEFILE_DELAY_UNTIL_REBOOT))
{
data->package->need_reboot = 1;
}
else
{
WARN("failed to schedule rename operation %s (error %d)\n", debugstr_w(path), GetLastError());
msi_free(tmppathW);
DeleteFileW( tmpfileW );
}
msi_free(tmpfileW);
}
else
WARN("failed to create %s (error %d)\n", debugstr_w(path), err);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment