1/*
2 * Copyright (C) by Olivier Goffart <ogoffart@owncloud.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15#pragma once
16
17#include "config.h"
18
19#include <QString>
20#include <ctime>
21
22#include <owncloudlib.h>
23// Chain in the base include and extend the namespace
24#include "common/filesystembase.h"
25
26class QFile;
27
28namespace OCC {
29
30/**
31 * \addtogroup libsync
32 * @{
33 */
34
35/**
36 * @brief This file contains file system helper
37 */
38namespace FileSystem {
39
40 /**
41 * @brief compare two files with given filename and return true if they have the same content
42 */
43 bool fileEquals(const QString &fn1, const QString &fn2);
44
45 /**
46 * @brief Get the mtime for a filepath
47 *
48 * Use this over QFileInfo::lastModified() to avoid timezone related bugs. See
49 * owncloud/core#9781 for details.
50 */
51 time_t OWNCLOUDSYNC_EXPORT getModTime(const QString &filename);
52
53 bool OWNCLOUDSYNC_EXPORT setModTime(const QString &filename, time_t modTime);
54
55 /**
56 * @brief Get the size for a file
57 *
58 * Use this over QFileInfo::size() to avoid bugs with lnk files on Windows.
59 * See https://bugreports.qt.io/browse/QTBUG-24831.
60 */
61 qint64 OWNCLOUDSYNC_EXPORT getSize(const QString &filename);
62
63 /**
64 * @brief Check if \a fileName has changed given previous size and mtime
65 *
66 * Nonexisting files are covered through mtime: they have an mtime of -1.
67 *
68 * @return true if the file's mtime or size are not what is expected.
69 */
70 bool OWNCLOUDSYNC_EXPORT fileChanged(const QString &fileName,
71 qint64 previousSize,
72 time_t previousMtime);
73
74 /**
75 * @brief Like !fileChanged() but with verbose logging if the file *did* change.
76 */
77 bool verifyFileUnchanged(const QString &fileName,
78 qint64 previousSize,
79 time_t previousMtime);
80}
81
82/** @} */
83}
84