cfengine  3.15.4
About: CFEngine is a configuration management system for configuring and maintaining Unix-like computers (using an own high level policy language). Community version.
  Fossies Dox: cfengine-3.15.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

files_names.c File Reference
#include <files_names.h>
#include <policy.h>
#include <promises.h>
#include <cf3.defs.h>
#include <dir.h>
#include <item_lib.h>
#include <files_interfaces.h>
#include <string_lib.h>
#include <known_dirs.h>
#include <conversion.h>
#include <cf-windows-functions.h>
Include dependency graph for files_names.c:

Go to the source code of this file.

Functions

bool IsNewerFileTree (const char *dir, time_t reftime)
 
bool IsDir (const char *path)
 
char * JoinSuffix (char *path, size_t path_size, const char *leaf)
 
char * JoinPaths (char *path, size_t path_size, const char *leaf_path)
 
bool IsAbsPath (const char *path)
 
void AddSlash (char *str)
 
char * GetParentDirectoryCopy (const char *path)
 
void DeleteSlash (char *str)
 
void DeleteRedundantSlashes (char *str)
 
const char * FirstFileSeparator (const char *str)
 
const char * LastFileSeparator (const char *str)
 
bool ChopLastNode (char *str)
 
void TransformNameInPlace (char *s, char from, char to)
 
char * CanonifyName (const char *str)
 
char * CanonifyChar (const char *str, char ch)
 
int CompareCSVName (const char *s1, const char *s2)
 
const char * ReadLastNode (const char *str)
 
bool CompressPath (char *dest, size_t dest_size, const char *src)
 
char * GetAbsolutePath (const char *path)
 
char * GetRealPath (const char *const path)
 
FilePathType FilePathGetType (const char *file_path)
 
bool IsFileOutsideDefaultRepository (const char *f)
 
static int UnixRootDirLength (const char *f)
 
int RootDirLength (const char *f)
 
const char * GetSoftwareCacheFilename (char *buffer)
 
const char * GetSoftwarePatchesFilename (char *buffer)
 
const char * RealPackageManager (const char *manager)
 

Function Documentation

◆ AddSlash()

void AddSlash ( char *  str)

◆ CanonifyChar()

char* CanonifyChar ( const char *  str,
char  ch 
)

Definition at line 494 of file files_names.c.

References CF_BUFSIZE, and strlcpy().

Referenced by ComparePackageVersionsInternal().

◆ CanonifyName()

◆ ChopLastNode()

◆ CompareCSVName()

int CompareCSVName ( const char *  s1,
const char *  s2 
)

Definition at line 514 of file files_names.c.

Referenced by ComparePackages().

◆ CompressPath()

bool CompressPath ( char *  dest,
size_t  dest_size,
const char *  src 
)

◆ DeleteRedundantSlashes()

void DeleteRedundantSlashes ( char *  str)

Definition at line 338 of file files_names.c.

References IsFileSep, and RootDirLength().

Referenced by ChopLastNode().

◆ DeleteSlash()

◆ FilePathGetType()

◆ FirstFileSeparator()

const char* FirstFileSeparator ( const char *  str)

Definition at line 375 of file files_names.c.

References IsFileSep, and NULL.

Referenced by ChopLastNode(), and GetParentDirectoryCopy().

◆ GetAbsolutePath()

char* GetAbsolutePath ( const char *  path)

Get absolute path of @path. If @path is already an absolute path this function just returns a compressed (see CompressPath()) copy of it. Otherwise this function prepends the curent working directory before @path and returns the result compressed with CompressPath(). If anything goes wrong, an empty string is returned.

WARNING: Remember to free return value.

Definition at line 642 of file files_names.c.

References CompressPath(), GetErrorStr(), IsAbsoluteFileName(), JoinPaths(), Log(), LOG_LEVEL_WARNING, NULL, NULL_OR_EMPTY, PATH_MAX, and xstrdup().

Referenced by AddPolicyEntryVariables(), and GetRealPath().

◆ GetParentDirectoryCopy()

char* GetParentDirectoryCopy ( const char *  path)

WARNING: Remember to free return value.

Definition at line 281 of file files_names.c.

References FirstFileSeparator(), free(), LastFileSeparator(), Log(), LOG_LEVEL_ERR, NULL, and xstrdup().

Referenced by MakeParentDirectory2().

◆ GetRealPath()

char* GetRealPath ( const char *const  path)

Definition at line 670 of file files_names.c.

References free(), GetAbsolutePath(), NOT_NULL_AND_EMPTY, NULL, NULL_OR_EMPTY, PATH_MAX, and xcalloc().

Referenced by RenameMainBundle().

◆ GetSoftwareCacheFilename()

const char* GetSoftwareCacheFilename ( char *  buffer)

◆ GetSoftwarePatchesFilename()

const char* GetSoftwarePatchesFilename ( char *  buffer)

Definition at line 806 of file files_names.c.

References CF_MAXVARSIZE, GetStateDir(), MapName(), and SOFTWARE_PATCHES_CACHE.

Referenced by GetLegacyPackagesMatching().

◆ IsAbsPath()

bool IsAbsPath ( const char *  path)

Definition at line 214 of file files_names.c.

References IsFileSep.

Referenced by CheckMeasureSanity(), KeepControlPromises(), SaveAsFile(), and VerifyName().

◆ IsDir()

bool IsDir ( const char *  path)

Definition at line 127 of file files_names.c.

References S_ISDIR.

Referenced by CheckAclDefault(), FnCallSysctlValue(), MakeParentDirectory2(), and SetACLDefaults().

◆ IsFileOutsideDefaultRepository()

bool IsFileOutsideDefaultRepository ( const char *  f)

Definition at line 722 of file files_names.c.

References GetInputDir(), and StringStartsWith().

Referenced by IsPolicyPrecheckNeeded().

◆ IsNewerFileTree()

bool IsNewerFileTree ( const char *  dir,
time_t  reftime 
)

◆ JoinPaths()

char* JoinPaths ( char *  path,
size_t  path_size,
const char *  leaf_path 
)

Just like the JoinSuffix() above, but makes sure there's a FILE_SEPARATOR between @path and @leaf_path. The only exception is the case where @path is "" and @leaf_path doesn't start with a FILE_SEPARATOR. In that case: JoinPaths("", PATH_MAX, "some_path") -> "some_path"

This function is similar to Python's os.path.join() except that unlike the Python function this one actually joins @path and @leaf_path even if @leaf_path starts with a FILE_SEPARATOR.

Definition at line 183 of file files_names.c.

References Chop(), FILE_SEPARATOR_STR, IsFileSep, Log(), LOG_LEVEL_ERR, NULL, strlcat(), and strnlen().

Referenced by GetAbsolutePath().

◆ JoinSuffix()

char* JoinSuffix ( char *  path,
size_t  path_size,
const char *  leaf 
)

Definition at line 152 of file files_names.c.

References Chop(), DeleteSlash(), Log(), LOG_LEVEL_ERR, NULL, and strlcat().

Referenced by CopyRegularFile(), and VerifyName().

◆ LastFileSeparator()

const char* LastFileSeparator ( const char *  str)

Definition at line 398 of file files_names.c.

References IsFileSep, and NULL.

Referenced by ChopLastNode(), GetParentDirectoryCopy(), MakeParentDirectory(), and ReadLastNode().

◆ ReadLastNode()

◆ RealPackageManager()

const char* RealPackageManager ( const char *  manager)

Detect whether package manager starts with an env command instead of package manager, and if so, return the real package manager.

Definition at line 813 of file files_names.c.

References CommandArg0().

Referenced by GetCachedPackageList(), PackageListInstalledFromCommand(), and ReportSoftware().

◆ RootDirLength()

int RootDirLength ( const char *  f)

◆ TransformNameInPlace()

void TransformNameInPlace ( char *  s,
char  from,
char  to 
)

Definition at line 469 of file files_names.c.

◆ UnixRootDirLength()

static int UnixRootDirLength ( const char *  f)
static

Definition at line 729 of file files_names.c.

References IsFileSep.

Referenced by RootDirLength().