Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
System
KCron
Commits
e6f5e2d2
Commit
e6f5e2d2
authored
Feb 23, 2022
by
Albert Astals Cid
Browse files
Write into crontab instead of replacing the file
Keeps permissions, owners, etc.
parent
3d66778a
Pipeline
#143261
passed with stage
in 48 seconds
Changes
1
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
src/helper/kcronhelper.cpp
View file @
e6f5e2d2
...
...
@@ -31,29 +31,38 @@
ActionReply
KcronHelper
::
save
(
const
QVariantMap
&
args
)
{
qCDebug
(
KCM_CRON_HELPER_LOG
)
<<
"running actions"
;
const
QString
source
=
args
[
QLatin1String
(
"source"
)].
toString
();
const
QString
destination
=
QStringLiteral
(
"/etc/crontab"
)
;
QByteArray
newCronData
;
{
QFile
destinationFile
(
destination
);
if
(
destinationFile
.
exists
()
&&
!
destinationFile
.
remove
())
{
const
QString
source
=
args
[
QLatin1String
(
"source"
)].
toString
();
QFile
sourceFile
(
source
);
if
(
!
sourceFile
.
open
(
QIODevice
::
ReadOnly
))
{
qCWarning
(
KCM_CRON_HELPER_LOG
)
<<
"can't open source file for reading"
<<
source
<<
sourceFile
.
errorString
();
ActionReply
reply
=
ActionReply
::
HelperErrorReply
();
qCWarning
(
KCM_CRON_HELPER_LOG
)
<<
"can't remove file"
<<
destinationFile
.
errorString
();
reply
.
setErrorDescription
(
destinationFile
.
errorString
());
reply
.
setErrorDescription
(
sourceFile
.
errorString
());
return
reply
;
}
newCronData
=
sourceFile
.
readAll
();
}
{
QFile
sourceFile
(
source
);
if
(
!
sourceFile
.
setPermissions
(
QFileDevice
::
ReadOwner
|
QFileDevice
::
WriteOwner
|
QFileDevice
::
ReadGroup
|
QFileDevice
::
ReadOther
))
{
qCWarning
(
KCM_CRON_HELPER_LOG
)
<<
"can't change permissions to 644"
;
}
if
(
!
sourceFile
.
copy
(
destination
))
{
qCWarning
(
KCM_CRON_HELPER_LOG
)
<<
"can't write into the system file"
<<
sourceFile
.
errorString
();
const
QString
destination
=
QStringLiteral
(
"/etc/crontab"
);
QFile
destinationFile
(
destination
);
if
(
!
destinationFile
.
open
(
QIODevice
::
WriteOnly
))
{
ActionReply
reply
=
ActionReply
::
HelperErrorReply
();
reply
.
setErrorDescription
(
sourceFile
.
errorString
());
qCWarning
(
KCM_CRON_HELPER_LOG
)
<<
"can't open destination file for writing"
<<
destinationFile
.
errorString
();
reply
.
setErrorDescription
(
destinationFile
.
errorString
());
return
reply
;
}
if
(
destinationFile
.
write
(
newCronData
)
<
0
)
{
ActionReply
reply
=
ActionReply
::
HelperErrorReply
();
qCWarning
(
KCM_CRON_HELPER_LOG
)
<<
"writing to destination file failed"
<<
destinationFile
.
errorString
();
reply
.
setErrorDescription
(
destinationFile
.
errorString
());
}
}
return
ActionReply
::
SuccessReply
();
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment