syncevolution/src/backends/file/FileSyncSource.h
Patrick Ohly 388f72b369 config: replaced overloaded "type" with "backend/databaseFormat/syncFormat/forceSyncFormat" (BMC #1023)
The meaning of "type" was horribly complex and had effects on the
backend and the peer. It was impossible to specify the sync format to
be used for a specific peer independently of the local backend and its
format, so adding a peer to a context broke the context configuration
(BMC #1023).

This is now fixed by splitting "type" into four independent properties:
- backend = plugin which interfaces with the data
- databaseFormat = data format used inside backend, only relevant for file backend
- syncFormat = data format preferred when talking to peer
- forceSyncFormat = disable format auto-negotiation, use preferred format

With that split, it is now possible to specify the format in which the
file backend stores items independently of the format in which they
are exchanged with the peer.

Old configurations with "type" can still be read. The values specified
inside it are transparently mapped to the new properties. Command line
and D-Bus API users will only see the new properties.

The command line tool still accepts "type" as an alias for the four new
properties. Using that has the same disadvantage as before: it will modify
the context even if only modifying the peer was intended.

The D-Bus API accepts only the new properties. Clients using "type"
must be adapted to the new property names. Clients not using that
continue to run unchanged.

Writing into the configuration requires a migration of the peer config
*and* the context in which it is defined. That is necessary because
the new semantic (independent database format) cannot be stored in the
old format. The migration is handled by rewriting first the context,
then all peers defined inside it.

Other user-visible changes:
- updated help texts
- the canonical "backend" value for the file backend is just "file"
  instead of the long "Files in one directory", which is now an alias
  (used to be the other way around); done because "type = file"
  was expanded to the long name, which was a bit unexpected and showed
  how unintuitive the long name is

Internal changes:
- getMimeVersion() is still present, although it hasn't been used
  for a long time; FileSyncSource::getMimeVersion() now derives
  the version from the supported Mime types, in case that the
  function will be needed again in the future
- setSourceType() with string as argument was replaced with one
  taking a SourceType instance; to emulate the old behavior if
  desired, construct SourceType from an old-style string
- ConfigProperty methods need to be virtual so that derived classes
  like SourceBackendConfigProperty can generate content at runtime
  (a recent commit broke that feature)
- File templates were stripped down to the essential properties,
  with "type" replaced by the per-peer "syncFormat".  "type" would
  still have been accepted (so it is not necessary to adapt
  syncevo-phone-config right away), but has the original
  disadvantage of modifying "backend" and "databaseFormat".
2011-02-03 12:59:02 +01:00

119 lines
4.1 KiB
C++

/*
* Copyright (C) 2007-2009 Patrick Ohly <patrick.ohly@gmx.de>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef INCL_FILESYNCSOURCE
#define INCL_FILESYNCSOURCE
#include <syncevo/TrackingSyncSource.h>
#ifdef ENABLE_FILE
#include <memory>
#include <boost/noncopyable.hpp>
#include <syncevo/declarations.h>
SE_BEGIN_CXX
/**
* Stores each SyncML item as a separate file in a directory. The
* directory has to be specified via the database name, using
* [file://]<path> as format. The file:// prefix is optional, but the
* directory is only created if it is used.
* SyncSource::getDatabaseID() gives us the database name.
*
* Change tracking is done via the file systems modification time
* stamp: editing a file treats it as modified and then sends it to
* the server in the next sync. Removing and adding files also works.
*
* The local unique identifier for each item is its name in the
* directory. New files are created using a running count which
* initialized based on the initial content of the directory to
* "highest existing number + 1" and incremented to avoid collisions.
*
* Although this sync source itself does not care about the content of
* each item/file, the server needs to know what each item sent to it
* contains and what items the source is able to receive. Therefore
* the "type" property for this source must contain a data format
* specified, including a version for it. Here are some examples:
* - type=file:text/vcard:3.0
* - type=file:text/plain:1.0
*/
class FileSyncSource : public TrackingSyncSource, private boost::noncopyable
{
public:
FileSyncSource(const SyncSourceParams &params,
const string &dataformat);
protected:
/* implementation of SyncSource interface */
virtual void open();
virtual bool isEmpty();
virtual void close();
virtual Databases getDatabases();
virtual std::string getMimeType() const;
virtual std::string getMimeVersion() const;
/* implementation of TrackingSyncSource interface */
virtual void listAllItems(RevisionMap_t &revisions);
virtual InsertItemResult insertItem(const string &luid, const std::string &item, bool raw);
void readItem(const std::string &luid, std::string &item, bool raw);
virtual void removeItem(const string &uid);
private:
/**
* @name values obtained from the source's "database format" configuration property
*
* Other sync sources only support one hard-coded type and
* don't need such variables.
*/
/**@{*/
string m_mimeType;
/**@}*/
/** directory selected via the database name in open(), reset in close() */
string m_basedir;
/** a counter which is used to name new files */
long m_entryCounter;
/**
* get access time for file, formatted as revision string
* @param filename absolute path or path relative to current directory
*/
string getATimeString(const string &filename);
/**
* create full filename from basedir and entry name
*/
string createFilename(const string &entry);
void getSynthesisInfo(SynthesisInfo &info,
XMLConfigFragments &fragments)
{
TrackingSyncSource::getSynthesisInfo(info, fragments);
// files can store all kinds of extensions, so tell
// engine to enable them
info.m_backendRule = "ALL";
}
};
SE_END_CXX
#endif // ENABLE_FILE
#endif // INCL_FILESYNCSOURCE