pianod2
multisource multiuser scriptable networked music player
Functions
fileio.h File Reference

Read/write JSON documents. More...

#include <config.h>
#include <string>
#include <parsnip/parsnip.h>
#include "fileio.h"
Include dependency graph for fileio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

const std::string & setupConfigDirectory (const char *location, const char *package, const char *nobody_name, const char *nobody_groups_list)
 Choose and configure a directory for configuration files. More...
 
bool carefullyWriteFile (std::string filename, Parsnip::Data &data)
 Write a document into a file. More...
 
const Parsnip::Data retrieveJsonFile (std::string filename, int minimumVersion=0)
 Restore from a file. More...
 

Detailed Description

Read/write JSON documents.

Function Documentation

◆ carefullyWriteFile()

bool carefullyWriteFile ( std::string  filename,
Parsnip::Data document 
)

Write a document into a file.

Write into a temporary file, and when complete, then rename files so as to keep as backup while moving the new file into place. If compression is supported, writes compressed file; otherwise, writes uncompressed JSON. This is set at compile time, with no run-time choice.

Parameters
filenameThe filename, without path.
documentThe document to write. Top level must be a document.
Warning
document parameter is altered to contain authoring package identification.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ retrieveJsonFile()

const Parsnip::Data retrieveJsonFile ( std::string  filename,
int  minimum_version 
)

Restore from a file.

Tries .gz (if supported) first, then falls back to uncompressed version.

Parameters
filenameThe filename, without path.
minimum_versionThe lowest file format version number supported. If the input file has a version number lower than this, a DataFormatException is thrown.
Returns
A parsed JSON document.
Exceptions
bad_alloc,io_base::failure,ora Parsnip serialization exception.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setupConfigDirectory()

const std::string& setupConfigDirectory ( const char *  location,
const char *  package,
const char *  nobody_name,
const char *  nobody_groups_list 
)

Choose and configure a directory for configuration files.

Parameters
locationPathname to use, or nullptr to use default.
packageName of this package.
nobody_nameName of user to run as, if running as root.
nobody_groups_listList of groups to adopt before giving up root privs.
Returns
Path of the chosen configuration directory, which will exist and be read/write accessible.
Here is the call graph for this function:
Here is the caller graph for this function: