1/*
2 This file is part of the KDE libraries
3
4 SPDX-FileCopyrightText: 1999 Waldo Bastian <bastian@kde.org>
5 SPDX-FileCopyrightText: 2006 Jaison Lee <lee.jaison@gmail.com>
6 SPDX-FileCopyrightText: 2011 Romain Perier <bambi@ubuntu.com>
7
8 SPDX-License-Identifier: LGPL-2.0-only
9*/
10
11#ifndef KBACKUP_H
12#define KBACKUP_H
13
14#include <QString>
15#include <kcoreaddons_export.h>
16
17/*!
18 * \namespace KBackup
19 * \inmodule KCoreAddons
20 *
21 * \brief Provides utility functions for backup of files.
22 */
23namespace KBackup
24{
25/*!
26 * \brief Function to create a backup file for a given filename.
27 *
28 * This function creates a backup file from the given filename.
29 * You can use this method even if you don't use KSaveFile.
30 *
31 * \a filename the file to backup
32 *
33 * \a backupDir optional directory where to save the backup file in.
34 * If empty (the default), the backup will be in the same directory as \a filename.
35 *
36 * \a backupExtension the extension to append to \a filename, "~" by default.
37 *
38 * Returns true if successful, or false if an error has occurred.
39 */
40KCOREADDONS_EXPORT bool simpleBackupFile(const QString &filename, const QString &backupDir = QString(), const QString &backupExtension = QStringLiteral("~"));
41
42/*!
43 * \brief Function to create a backup file for a given filename.
44 *
45 * This function creates a series of numbered backup files from the
46 * given filename.
47 *
48 * The backup file names will be of the form:
49 * \<name\>.\<number\>\<extension\>
50 * for instance
51 * \badcode
52 * chat.3.log
53 * \endcode
54 *
55 * The new backup file will be have the backup number 1.
56 * Each existing backup file will have its number incremented by 1.
57 * Any backup files with numbers greater than the maximum number
58 * permitted (\a maxBackups) will be removed.
59 * You can use this method even if you don't use KSaveFile.
60 *
61 * \a filename the file to backup
62 *
63 * \a backupDir optional directory where to save the backup file in.
64 * If empty (the default), the backup will be in the same directory as \a filename.
65 *
66 * \a backupExtension the extension to append to \a filename,
67 * which is "~" by default. Do not use an extension containing digits.
68 *
69 * \a maxBackups the maximum number of backup files permitted.
70 * For best performance a small number (10) is recommended.
71 *
72 * Returns \c true if successful, or false if an error has occurred.
73 */
74KCOREADDONS_EXPORT bool numberedBackupFile(const QString &filename,
75 const QString &backupDir = QString(),
76 const QString &backupExtension = QStringLiteral("~"),
77 const uint maxBackups = 10);
78}
79
80#endif
81

source code of kcoreaddons/src/lib/io/kbackup.h