1. Overview
The CronTab module provides Cron schedule management for BastionGuard Backup. It reads and rewrites user crontabs and installs or removes periodic script files below the system cron directories.
The implementation is written in Vala and uses GLib/GIO together with the application utility namespaces required by the file.
2. Dependencies and Integration
The module imports:
TeeJee.LoggingTeeJee.FileSystemTeeJee.ProcessHelperTeeJee.Misc
Key runtime integrations include:
- Gee – typed lists, maps, queues, or collection operations
3. Declared Types
3.1 CronTab
public class CronTab : GLib.Object
This class encapsulates the state and operations described by this source file.
4. State, Properties, Constants, and Signals
Public and protected state
public static string crontab_text– Cached crontab content reused by multiple operations.
5. Public API and Operational Methods
5.1 clear_cached_text()
public static void clear_cached_text()
Implements the clear cached text operation for this module.
5.2 crontab_read_all()
public static string crontab_read_all(string user_name = "")
Executes crontab listing for the current or specified user and returns the complete installed table, or an empty string on failure.
- Executes an external process or generated shell command and uses its return status as part of the result.
5.3 has_job()
public static bool has_job(string entry, bool partial_match, bool use_cached_text)
Evaluates has job and returns a Boolean capability or state result.
5.4 add_job()
public static bool add_job(string entry, bool use_cached_text)
Creates or appends job to the relevant GTK container, collection, or system configuration.
- Executes an external process or generated shell command and uses its return status as part of the result.
- Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
5.5 remove_job()
public static bool remove_job(string entry, bool use_regex, bool use_cached_text)
Removes job and reports whether cleanup completed successfully.
- Executes an external process or generated shell command and uses its return status as part of the result.
- Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
- Uses regular expressions to parse or validate text output.
- Catches runtime errors locally and reports them through the logging layer or return value.
5.6 install()
public static bool install(string file_path, string user_name = "")
Implements the install operation for this module.
- Executes an external process or generated shell command and uses its return status as part of the result.
5.7 export()
public static bool export(string file_path, string user_name = "")
Implements the export operation for this module.
- Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
5.8 import()
public static bool import(string file_path, string user_name = "")
Implements the import operation for this module.
5.9 add_script_file()
public static bool add_script_file(string file_name, string cron_dir_type, string text, bool stop_cron_emails)
Creates a system cron script in the requested periodic directory, adds the shell header and optional output suppression, and sets executable permissions.
- Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
5.10 remove_script_file()
public static bool remove_script_file(string file_name, string cron_dir_type)
Removes script file and reports whether cleanup completed successfully.
- Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
6. Filesystem Paths and Resource Locations
The source references the following absolute or template paths:
/etc/cron.%s/%s
Some values are templates completed at runtime with application names, process IDs, device identifiers, or file names.
7. External Commands and System Interfaces
The module constructs, checks, or parses commands containing:
Failed to export crontab file
Failed to install crontab file
SHELL=/bin/bash
crontab
crontab -l
crontab \"%s\"
crontab file exported
crontab file installed
Execution success is determined from command exit status and, where applicable, parsed standard output or standard error.
8. Operational Flow
- Apply the requested operation and update runtime or persistent state.
- Finalize the operation and release files, mounts, child processes, widgets, or cached state.
9. Error Handling and Diagnostics
- GLib and filesystem exceptions are caught locally in the operations that can fail.
- The TeeJee logging layer records errors, debug state, generated commands, and operational messages.
- Boolean, nullable, or empty-string return values communicate recoverable failures to callers.
10. Runtime and Security Considerations
- External commands: command availability, quoting, locale, privileges, and output format can affect behavior.
- Dynamic command construction: caller-controlled values must be validated and escaped before being inserted into shell commands.
- Linux-specific paths: the module depends on Linux virtual filesystems or privileged system directories.
- Shared state: static caches and global switches are shared by all callers and are not automatically thread-isolated.
11. Licensing
The source is distributed under the GNU General Public License version 2 or any later version.
The source header identifies:
Copyright 2012-2018 Tony George <teejeetech@gmail.com>
