LibreOffice Module onlineupdate (master) 1
Classes | Macros | Functions | Variables
updater.cxx File Reference
#include "bspatch.h"
#include "progressui.h"
#include "archivereader.h"
#include "readstrings.h"
#include "errors.h"
#include "bzlib.h"
#include <thread>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <limits.h>
#include <errno.h>
#include <algorithm>
#include <memory>
#include <config_version.h>
#include "updatelogging.h"
#include <onlineupdate/mozilla/Compiler.h>
#include <onlineupdate/mozilla/Types.h>
Include dependency graph for updater.cxx:

Go to the source code of this file.

Classes

class  AutoFile
 
struct  MARChannelStringTable
 
struct  copy_recursive_skiplist< N >
 
class  Action
 
class  RemoveFile
 
class  RemoveDir
 
class  AddFile
 
class  PatchFile
 
class  AddIfFile
 
class  AddIfNotFile
 
class  PatchIfFile
 
class  ActionList
 

Macros

#define PROGRESS_PREPARE_SIZE   20.0f
 
#define PROGRESS_EXECUTE_SIZE   75.0f
 
#define PROGRESS_FINISH_SIZE   5.0f
 
#define SSIZE_MAX   LONG_MAX
 
#define USE_EXECV
 
#define SKIPLIST_COUNT   3
 

Functions

static unsigned int crc32 (const unsigned char *buf, unsigned int len)
 
static NS_tcharmstrtok (const NS_tchar *delims, NS_tchar **str)
 
static NS_tcharnew_absolute_path (const NS_tchar *relpath)
 Converts a relative update path to an absolute path related to the working or install directory. More...
 
static const NS_tcharget_relative_offset (const NS_tchar *abs_path)
 Get a pointer in the absolute path, relative to the working or install directory. More...
 
static NS_tcharget_valid_path (NS_tchar **line, bool isdir=false)
 Gets the platform specific path and performs simple checks to the path. More...
 
static NS_tcharget_quoted_path (const NS_tchar *path)
 
static void ensure_write_permissions (const NS_tchar *path)
 
static int ensure_remove (const NS_tchar *path)
 
static int ensure_remove_recursive (const NS_tchar *path, bool continueEnumOnFailure=false)
 
static bool is_read_only (const NS_tchar *flags)
 
static FILE * ensure_open (const NS_tchar *path, const NS_tchar *flags, unsigned int options)
 
static int ensure_parent_dir (const NS_tchar *path)
 
static int ensure_copy_symlink (const NS_tchar *path, const NS_tchar *dest)
 
static int ensure_copy (const NS_tchar *path, const NS_tchar *dest)
 
template<unsigned N>
static int ensure_copy_recursive (const NS_tchar *path, const NS_tchar *dest, copy_recursive_skiplist< N > &skiplist)
 
static int rename_file (const NS_tchar *spath, const NS_tchar *dpath, bool allowDirs=false)
 
static int backup_create (const NS_tchar *path)
 
static int backup_restore (const NS_tchar *path, const NS_tchar *relPath)
 
static int backup_discard (const NS_tchar *path, const NS_tchar *relPath)
 
static void backup_finish (const NS_tchar *path, const NS_tchar *relPath, int status)
 
static int DoUpdate (ArchiveReader &ArchiveReader)
 
static void LaunchCallbackApp (const NS_tchar *workingDir, int argc, NS_tchar **argv, bool usingService)
 
static bool WriteStatusFile (const char *aStatus)
 
static void WriteStatusFile (int status)
 
static int CopyInstallDirToDestDir ()
 
static int ProcessReplaceRequest ()
 
static int GetUpdateFileNames (std::vector< tstring > &fileNames)
 
static int CheckSignature (ArchiveReader &archiveReader)
 
static void UpdateThreadFunc (void *)
 
int LaunchCallbackAndPostProcessApps (int argc, NS_tchar **argv, int callbackIndex)
 
int NS_main (int argc, NS_tchar **argv)
 
int add_dir_entries (const NS_tchar *dirpath, ActionList *list)
 
static NS_tcharGetManifestContents (const NS_tchar *manifest)
 
int AddPreCompleteActions (ActionList *list)
 

Variables

unsigned int BZ2_crc32Table [256]
 
static NS_tchargPatchDirPath
 
static NS_tchar gInstallDirPath [MAXPATHLEN]
 
static NS_tchar gWorkingDirPath [MAXPATHLEN]
 
static bool gSucceeded = false
 
static bool sStagedUpdate = false
 
static bool sReplaceRequest = false
 
static bool sUsingService = false
 
static const NS_tchar kWhitespace [] = NS_T(" \t")
 
static const NS_tchar kNL [] = NS_T("\r\n")
 
static const NS_tchar kQuote [] = NS_T("\"")
 

Macro Definition Documentation

◆ PROGRESS_EXECUTE_SIZE

#define PROGRESS_EXECUTE_SIZE   75.0f

Definition at line 81 of file updater.cxx.

◆ PROGRESS_FINISH_SIZE

#define PROGRESS_FINISH_SIZE   5.0f

Definition at line 82 of file updater.cxx.

◆ PROGRESS_PREPARE_SIZE

#define PROGRESS_PREPARE_SIZE   20.0f

Manifest Format

contents = 1*( line ) line = method LWS *( param LWS ) CRLF CRLF = "\r\n" LWS = 1*( " " | "\t" )

Available methods for the manifest file:

updatev2.manifest

method = "add" | "add-if" | "patch" | "patch-if" | "remove" | "rmdir" | "rmrfdir" | type

'type' is the update type (e.g. complete or partial) and when present MUST be the first entry in the update manifest. The type is used to support downgrades by causing the actions defined in precomplete to be performed.

updatev3.manifest

method = "add" | "add-if" | "add-if-not" | "patch" | "patch-if" | "remove" | "rmdir" | "rmrfdir" | type

'add-if-not' adds a file if it doesn't exist.

precomplete

method = "remove" | "rmdir"

Definition at line 80 of file updater.cxx.

◆ SKIPLIST_COUNT

#define SKIPLIST_COUNT   3

◆ SSIZE_MAX

#define SSIZE_MAX   LONG_MAX

Definition at line 107 of file updater.cxx.

◆ USE_EXECV

#define USE_EXECV

Definition at line 113 of file updater.cxx.

Function Documentation

◆ add_dir_entries()

int add_dir_entries ( const NS_tchar dirpath,
ActionList list 
)

◆ AddPreCompleteActions()

int AddPreCompleteActions ( ActionList list)

◆ backup_create()

static int backup_create ( const NS_tchar path)
static

◆ backup_discard()

static int backup_discard ( const NS_tchar path,
const NS_tchar relPath 
)
static

◆ backup_finish()

static void backup_finish ( const NS_tchar path,
const NS_tchar relPath,
int  status 
)
static

Definition at line 1072 of file updater.cxx.

References backup_discard(), backup_restore(), and OK.

Referenced by RemoveFile::Finish(), AddFile::Finish(), and PatchFile::Finish().

◆ backup_restore()

static int backup_restore ( const NS_tchar path,
const NS_tchar relPath 
)
static

Definition at line 998 of file updater.cxx.

References BACKUP_EXT, LOG, LOG_S, MAXPATHLEN, NS_T, NS_taccess, NS_tsnprintf, OK, and rename_file().

Referenced by backup_finish().

◆ CheckSignature()

static int CheckSignature ( ArchiveReader archiveReader)
static

◆ CopyInstallDirToDestDir()

static int CopyInstallDirToDestDir ( )
static

◆ crc32()

static unsigned int crc32 ( const unsigned char *  buf,
unsigned int  len 
)
static

Definition at line 159 of file updater.cxx.

References BZ2_crc32Table, and end.

Referenced by PatchFile::LoadSourceFile().

◆ DoUpdate()

int DoUpdate ( ArchiveReader ArchiveReader)
static

◆ ensure_copy()

static int ensure_copy ( const NS_tchar path,
const NS_tchar dest 
)
static

◆ ensure_copy_recursive()

template<unsigned N>
static int ensure_copy_recursive ( const NS_tchar path,
const NS_tchar dest,
copy_recursive_skiplist< N > &  skiplist 
)
static

◆ ensure_copy_symlink()

static int ensure_copy_symlink ( const NS_tchar path,
const NS_tchar dest 
)
static

Definition at line 644 of file updater.cxx.

References LOG, LOG_S, MAXPATHLEN, NS_T, and READ_ERROR.

Referenced by ensure_copy(), and ensure_copy_recursive().

◆ ensure_open()

static FILE * ensure_open ( const NS_tchar path,
const NS_tchar flags,
unsigned int  options 
)
static

◆ ensure_parent_dir()

static int ensure_parent_dir ( const NS_tchar path)
static

◆ ensure_remove()

static int ensure_remove ( const NS_tchar path)
static

Definition at line 491 of file updater.cxx.

References ensure_write_permissions(), LOG, LOG_S, and NS_tremove.

Referenced by backup_discard(), ensure_remove_recursive(), and rename_file().

◆ ensure_remove_recursive()

static int ensure_remove_recursive ( const NS_tchar path,
bool  continueEnumOnFailure = false 
)
static

◆ ensure_write_permissions()

static void ensure_write_permissions ( const NS_tchar path)
static

Definition at line 478 of file updater.cxx.

Referenced by ensure_open(), ensure_remove(), and ensure_remove_recursive().

◆ get_quoted_path()

static NS_tchar * get_quoted_path ( const NS_tchar path)
static

Definition at line 456 of file updater.cxx.

References kQuote, NS_T, NS_tstrcat, NS_tstrcpy, and NS_tstrlen.

Referenced by add_dir_entries().

◆ get_relative_offset()

static const NS_tchar * get_relative_offset ( const NS_tchar abs_path)
static

Get a pointer in the absolute path, relative to the working or install directory.

Returns itself, if not absolute or outside of the directory.

Parameters
abs_pathAn absolute path. return pointer to the location within fullpath where the relative path starts or fullpath itself if it already looks relative.

Definition at line 371 of file updater.cxx.

References gInstallDirPath, gWorkingDirPath, NS_tstrlen, prefix, and sStagedUpdate.

Referenced by add_dir_entries().

◆ get_valid_path()

static NS_tchar * get_valid_path ( NS_tchar **  line,
bool  isdir = false 
)
static

Gets the platform specific path and performs simple checks to the path.

If the path checks don't pass nullptr will be returned.

Parameters
lineThe line from the manifest that contains the path.
isdirWhether the path is a directory path. Defaults to false.
Returns
valid filesystem path or nullptr if the path checks fail.

Definition at line 405 of file updater.cxx.

References kQuote, line, LOG, LOG_S, mstrtok(), NS_T, NS_tstrlen, and NS_tstrstr.

Referenced by RemoveFile::Parse(), RemoveDir::Parse(), AddFile::Parse(), PatchFile::Parse(), AddIfFile::Parse(), AddIfNotFile::Parse(), and PatchIfFile::Parse().

◆ GetManifestContents()

static NS_tchar * GetManifestContents ( const NS_tchar manifest)
static

Definition at line 4329 of file updater.cxx.

References count, FILE, LOG, LOG_S, NS_T, NS_tfopen, and SSIZE_MAX.

Referenced by AddPreCompleteActions(), and DoUpdate().

◆ GetUpdateFileNames()

static int GetUpdateFileNames ( std::vector< tstring > &  fileNames)
static

◆ is_read_only()

static bool is_read_only ( const NS_tchar flags)
static

Definition at line 561 of file updater.cxx.

References length, NS_T, NS_tstrcmp, and NS_tstrlen.

Referenced by ensure_open().

◆ LaunchCallbackAndPostProcessApps()

int LaunchCallbackAndPostProcessApps ( int  argc,
NS_tchar **  argv,
int  callbackIndex 
)

◆ LaunchCallbackApp()

static void LaunchCallbackApp ( const NS_tchar workingDir,
int  argc,
NS_tchar **  argv,
bool  usingService 
)
static

Definition at line 2140 of file updater.cxx.

References LaunchChild(), LOG, NS_tchdir, and WinLaunchChild().

Referenced by LaunchCallbackAndPostProcessApps(), and NS_main().

◆ mstrtok()

static NS_tchar * mstrtok ( const NS_tchar delims,
NS_tchar **  str 
)
static

◆ new_absolute_path()

static NS_tchar * new_absolute_path ( const NS_tchar relpath)
static

Converts a relative update path to an absolute path related to the working or install directory.

Allocates a new NS_tchar[] based path!

Parameters
relpathThe relative path to convert to a full path.
Returns
valid filesystem full path or nullptr if memory allocation fails.

Definition at line 312 of file updater.cxx.

References gInstallDirPath, gWorkingDirPath, NS_T, NS_tstrcat, NS_tstrcpy, NS_tstrlen, and sStagedUpdate.

Referenced by add_dir_entries(), AddPreCompleteActions(), RemoveFile::Parse(), RemoveDir::Parse(), AddFile::Parse(), PatchFile::Parse(), AddIfFile::Parse(), AddIfNotFile::Parse(), and PatchIfFile::Parse().

◆ NS_main()

int NS_main ( int  argc,
NS_tchar **  argv 
)

◆ ProcessReplaceRequest()

static int ProcessReplaceRequest ( )
static

◆ rename_file()

static int rename_file ( const NS_tchar spath,
const NS_tchar dpath,
bool  allowDirs = false 
)
static

◆ UpdateThreadFunc()

static void UpdateThreadFunc ( void *  )
static

◆ WriteStatusFile() [1/2]

static bool WriteStatusFile ( const char *  aStatus)
static

◆ WriteStatusFile() [2/2]

static void WriteStatusFile ( int  status)
static

Definition at line 2220 of file updater.cxx.

References OK, sStagedUpdate, text(), and WriteStatusFile().

Variable Documentation

◆ BZ2_crc32Table

unsigned int BZ2_crc32Table[256]

Definition at line 155 of file updater.cxx.

Referenced by crc32().

◆ gInstallDirPath

NS_tchar gInstallDirPath[MAXPATHLEN]
static

◆ gPatchDirPath

NS_tchar* gPatchDirPath
static

◆ gSucceeded

bool gSucceeded = false
static

◆ gWorkingDirPath

NS_tchar gWorkingDirPath[MAXPATHLEN]
static

◆ kNL

const NS_tchar kNL[] = NS_T("\r\n")
static

Definition at line 240 of file updater.cxx.

Referenced by AddPreCompleteActions(), and DoUpdate().

◆ kQuote

const NS_tchar kQuote[] = NS_T("\"")
static

◆ kWhitespace

const NS_tchar kWhitespace[] = NS_T(" \t")
static

Definition at line 239 of file updater.cxx.

Referenced by AddPreCompleteActions(), and DoUpdate().

◆ sReplaceRequest

bool sReplaceRequest = false
static

Definition at line 228 of file updater.cxx.

Referenced by backup_discard(), NS_main(), and UpdateThreadFunc().

◆ sStagedUpdate

bool sStagedUpdate = false
static

◆ sUsingService

bool sUsingService = false
static

Definition at line 229 of file updater.cxx.

Referenced by LaunchCallbackAndPostProcessApps(), NS_main(), and UpdateThreadFunc().