Commit d8797e69 authored by Robert Dailey's avatar Robert Dailey
Browse files

File copy/install permissions code modifying timestamps

When invoking file(COPY) or file(INSTALL), the flow is:

    Copy File -> Modify Timestamps -> Set Permissions

Now the flow is:

    Copy File -> Set Permissions -> Modify Timestamps

Setting permissions after modifying the timestamps causes the timestamps
to be modified *again*, resulting in the timestamps being set to the
current clock time instead of the timestamp of the source file of the
copy.

Additionally, none of the above 3 operations are performed if the two
file timestamps (source & destination) are the same.

Fixes #17087
parent a8d8d2fd
Pipeline #65330 passed with stage
......@@ -1571,42 +1571,49 @@ bool cmFileCopier::InstallFile(const char* fromFile, const char* toFile,
// Inform the user about this file installation.
this->ReportCopy(toFile, TypeFile, copy);
// Copy the file.
if (copy && !cmSystemTools::CopyAFile(fromFile, toFile, true)) {
std::ostringstream e;
e << this->Name << " cannot copy file \"" << fromFile << "\" to \""
<< toFile << "\".";
this->FileCommand->SetError(e.str());
return false;
}
// Set the file modification time of the destination file.
if (copy && !this->Always) {
// Add write permission so we can set the file time.
// Permissions are set unconditionally below anyway.
mode_t perm = 0;
if (cmSystemTools::GetPermissions(toFile, perm)) {
cmSystemTools::SetPermissions(toFile, perm | mode_owner_write);
}
if (!cmSystemTools::CopyFileTime(fromFile, toFile)) {
if (copy) {
// Copy the file.
if (!cmSystemTools::CopyAFile(fromFile, toFile, true)) {
std::ostringstream e;
e << this->Name << " cannot set modification time on \"" << toFile
<< "\"";
e << this->Name << " cannot copy file \"" << fromFile << "\" to \""
<< toFile << "\".";
this->FileCommand->SetError(e.str());
return false;
}
}
// Set permissions of the destination file.
mode_t permissions =
(match_properties.Permissions ? match_properties.Permissions
: this->FilePermissions);
if (!permissions) {
// No permissions were explicitly provided but the user requested
// that the source file permissions be used.
cmSystemTools::GetPermissions(fromFile, permissions);
// Set permissions of the destination file.
mode_t permissions =
(match_properties.Permissions ? match_properties.Permissions
: this->FilePermissions);
if (!permissions) {
// No permissions were explicitly provided but the user requested
// that the source file permissions be used.
cmSystemTools::GetPermissions(fromFile, permissions);
}
if (!this->SetPermissions(toFile, permissions)) {
return false;
}
// Set the file modification time of the destination file.
if (!this->Always) {
// Add write permission so we can set the file time.
// Permissions are set unconditionally below anyway.
mode_t perm = 0;
if (cmSystemTools::GetPermissions(toFile, perm)) {
cmSystemTools::SetPermissions(toFile, perm | mode_owner_write);
}
if (!cmSystemTools::CopyFileTime(fromFile, toFile)) {
std::ostringstream e;
e << this->Name << " cannot set modification time on \"" << toFile
<< "\"";
this->FileCommand->SetError(e.str());
return false;
}
}
}
return this->SetPermissions(toFile, permissions);
return true;
}
bool cmFileCopier::InstallDirectory(const char* source,
......
Supports Markdown
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