Blender V4.3
bpath.cc File Reference
#include <sys/stat.h>
#include <cstring>
#include <dirent.h>
#include <unistd.h>
#include "MEM_guardedalloc.h"
#include "BLI_fileops.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "DEG_depsgraph.hh"
#include "BKE_idtype.hh"
#include "BKE_main.hh"
#include "BKE_node.hh"
#include "BKE_report.hh"
#include "BKE_bpath.hh"
#include "CLG_log.h"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Classes

struct  BPathFind_Data
 
struct  BPathRebase_Data
 
struct  BPathRemap_Data
 
struct  PathStore
 

Functions

Generic Utilities
void BKE_bpath_summary_report (const BPathSummary &summary, ReportList *reports)
 
Generic File Path Traversal API
void BKE_bpath_foreach_path_id (BPathForeachPathData *bpath_data, ID *id)
 
void BKE_bpath_foreach_path_main (BPathForeachPathData *bpath_data)
 
bool BKE_bpath_foreach_path_fixed_process (BPathForeachPathData *bpath_data, char *path, size_t path_maxncpy)
 
bool BKE_bpath_foreach_path_dirfile_fixed_process (BPathForeachPathData *bpath_data, char *path_dir, size_t path_dir_maxncpy, char *path_file, size_t path_file_maxncpy)
 
bool BKE_bpath_foreach_path_allocated_process (BPathForeachPathData *bpath_data, char **path)
 
Check Missing Files
static bool check_missing_files_foreach_path_cb (BPathForeachPathData *bpath_data, char *, size_t, const char *path_src)
 
void BKE_bpath_missing_files_check (Main *bmain, ReportList *reports)
 
Rebase Relative Paths
static bool relative_rebase_foreach_path_cb (BPathForeachPathData *bpath_data, char *path_dst, size_t path_dst_maxncpy, const char *path_src)
 
void BKE_bpath_relative_rebase (Main *bmain, const char *basedir_src, const char *basedir_dst, ReportList *reports, BPathSummary *r_summary)
 
Make Paths Relative Or Absolute
static bool relative_convert_foreach_path_cb (BPathForeachPathData *bpath_data, char *path_dst, size_t path_dst_maxncpy, const char *path_src)
 
static bool absolute_convert_foreach_path_cb (BPathForeachPathData *bpath_data, char *path_dst, size_t path_dst_maxncpy, const char *path_src)
 
static void bpath_absolute_relative_convert (Main *bmain, const char *basedir, ReportList *reports, BPathForeachPathFunctionCallback callback_function, BPathSummary *r_summary)
 
void BKE_bpath_relative_convert (Main *bmain, const char *basedir, ReportList *reports, BPathSummary *r_summary)
 
void BKE_bpath_absolute_convert (Main *bmain, const char *basedir, ReportList *reports, BPathSummary *r_summary)
 
Backup/Restore/Free paths list functions.
static bool bpath_list_append (BPathForeachPathData *bpath_data, char *, size_t, const char *path_src)
 
static bool bpath_list_restore (BPathForeachPathData *bpath_data, char *path_dst, size_t path_dst_maxncpy, const char *path_src)
 
void * BKE_bpath_list_backup (Main *bmain, const eBPathForeachFlag flag)
 
void BKE_bpath_list_restore (Main *bmain, const eBPathForeachFlag flag, void *path_list_handle)
 
void BKE_bpath_list_free (void *path_list_handle)
 

Variables

static CLG_LogRef LOG = {"bke.bpath"}
 

Find Missing Files

#define MAX_DIR_RECURSE   16
 
#define FILESIZE_INVALID_DIRECTORY   -1
 
static bool missing_files_find__recursive (const char *search_directory, const char *filename_src, char r_filepath_new[FILE_MAX], int64_t *r_filesize, int *r_recurse_depth)
 
static bool missing_files_find_foreach_path_cb (BPathForeachPathData *bpath_data, char *path_dst, size_t path_dst_maxncpy, const char *path_src)
 
void BKE_bpath_missing_files_find (Main *bmain, const char *searchpath, ReportList *reports, const bool find_all)
 

Macro Definition Documentation

◆ FILESIZE_INVALID_DIRECTORY

#define FILESIZE_INVALID_DIRECTORY   -1

Definition at line 275 of file bpath.cc.

Referenced by missing_files_find__recursive(), and missing_files_find_foreach_path_cb().

◆ MAX_DIR_RECURSE

#define MAX_DIR_RECURSE   16

Definition at line 274 of file bpath.cc.

Referenced by missing_files_find__recursive().

Function Documentation

◆ absolute_convert_foreach_path_cb()

static bool absolute_convert_foreach_path_cb ( BPathForeachPathData * bpath_data,
char * path_dst,
size_t path_dst_maxncpy,
const char * path_src )
static

◆ BKE_bpath_absolute_convert()

void BKE_bpath_absolute_convert ( Main * bmain,
const char * basedir,
ReportList * reports,
BPathSummary * r_summary = nullptr )

Make all relative file paths in given bmain absolute, using given basedir as root.

Definition at line 624 of file bpath.cc.

References absolute_convert_foreach_path_cb(), and bpath_absolute_relative_convert().

Referenced by BKE_main_merge(), BLO_write_file_impl(), make_paths_absolute_exec(), and blender::bke::tests::TEST_F().

◆ BKE_bpath_foreach_path_allocated_process()

bool BKE_bpath_foreach_path_allocated_process ( BPathForeachPathData * bpath_data,
char ** path )

Run the callback on a path, replacing the content of the string as needed.

Parameters
pathA pointer to a MEM-allocated string. If modified, it will be freed and replaced by a new allocated string.
Note
path is expected to be FILE_MAX size or smaller.
Returns
true is path was modified and re-allocated, false otherwise.

Definition at line 185 of file bpath.cc.

References BPathForeachPathData::absolute_base_path, BLI_path_abs(), BLI_strdup(), BPathForeachPathData::callback_function, FILE_MAX, BPathForeachPathData::is_path_modified, MEM_freeN(), and STRNCPY.

Referenced by text_foreach_path().

◆ BKE_bpath_foreach_path_dirfile_fixed_process()

bool BKE_bpath_foreach_path_dirfile_fixed_process ( BPathForeachPathData * bpath_data,
char * path_dir,
size_t path_dir_maxncpy,
char * path_file,
size_t path_file_maxncpy )

Run the callback on a (directory + file) path, replacing the content of the two strings as needed.

Parameters
path_dirA fixed, FILE_MAXDIR-sized char buffer.
path_fileA fixed, FILE_MAXFILE-sized char buffer.
Returns
true is path_dir and/or path_file were modified, false otherwise.

Definition at line 154 of file bpath.cc.

References BPathForeachPathData::absolute_base_path, BLI_path_abs(), BLI_path_join, BLI_path_split_dir_file(), BPathForeachPathData::callback_function, FILE_MAX, BPathForeachPathData::is_path_modified, and STRNCPY.

Referenced by seq_foreach_path_callback().

◆ BKE_bpath_foreach_path_fixed_process()

bool BKE_bpath_foreach_path_fixed_process ( BPathForeachPathData * bpath_data,
char * path,
size_t path_maxncpy )

◆ BKE_bpath_foreach_path_id()

◆ BKE_bpath_foreach_path_main()

◆ BKE_bpath_list_backup()

void * BKE_bpath_list_backup ( Main * bmain,
eBPathForeachFlag flag )

Temp backup of paths from all IDs in given bmain.

Returns
An opaque handle to pass to BKE_bpath_list_restore and BKE_bpath_list_free.

Definition at line 689 of file bpath.cc.

References BKE_bpath_foreach_path_main(), BPathForeachPathData::bmain, bpath_list_append(), flag, and MEM_callocN.

Referenced by BLO_write_file_impl(), and blender::bke::tests::TEST_F().

◆ BKE_bpath_list_free()

void BKE_bpath_list_free ( void * path_list_handle)

Free the temp backup of paths in path_list_handle.

Note
This function assumes that the path list has already been restored with a call to BKE_bpath_list_restore, and is therefore empty.

Definition at line 715 of file bpath.cc.

References BLI_assert, BLI_freelistN(), BLI_listbase_is_empty(), and MEM_freeN().

Referenced by BLO_write_file_impl(), and blender::bke::tests::TEST_F().

◆ BKE_bpath_list_restore()

void BKE_bpath_list_restore ( Main * bmain,
eBPathForeachFlag flag,
void * path_list_handle )

Restore the temp backup of paths from path_list_handle into all IDs in given bmain.

Note
This function assumes that the data in given Main did not change (no addition/deletion/re-ordering of IDs, or their file paths) since the call to BKE_bpath_list_backup that generated the given path_list_handle.

Definition at line 703 of file bpath.cc.

References BKE_bpath_foreach_path_main(), BPathForeachPathData::bmain, bpath_list_restore(), and flag.

Referenced by BLO_write_file_impl(), and blender::bke::tests::TEST_F().

◆ BKE_bpath_missing_files_check()

◆ BKE_bpath_missing_files_find()

void BKE_bpath_missing_files_find ( Main * bmain,
const char * searchpath,
ReportList * reports,
bool find_all )

Recursively search into given search directory, for all file paths of all IDs in given bmain, and replace existing paths as needed.

Note
The search will happen into the whole search directory tree recursively (with a limit of MAX_DIR_RECURSE), if several files are found matching a searched filename, the biggest one will be used. This is so that things like thumbnails don't get selected instead of the actual image e.g.
Parameters
searchpathThe root directory in which the new filepaths should be searched for.
find_allIf true, also search for files which current path is still valid, if false skip those still valid paths.

Definition at line 404 of file bpath.cc.

References BPathFind_Data::basedir, BKE_BPATH_FOREACH_PATH_ABSOLUTE, BKE_bpath_foreach_path_main(), BKE_BPATH_FOREACH_PATH_RELOAD_EDITED, BKE_BPATH_FOREACH_PATH_RESOLVE_TOKEN, BKE_BPATH_TRAVERSE_SKIP_WEAK_REFERENCES, BKE_main_blendfile_path(), BPathForeachPathData::bmain, data, flag, and missing_files_find_foreach_path_cb().

Referenced by find_missing_files_exec().

◆ BKE_bpath_relative_convert()

void BKE_bpath_relative_convert ( Main * bmain,
const char * basedir,
ReportList * reports,
BPathSummary * r_summary = nullptr )

Make all absolute file paths in given bmain relative to given basedir.

Definition at line 615 of file bpath.cc.

References bpath_absolute_relative_convert(), and relative_convert_foreach_path_cb().

Referenced by BLO_write_file_impl(), make_paths_relative_exec(), and blender::bke::tests::TEST_F().

◆ BKE_bpath_relative_rebase()

void BKE_bpath_relative_rebase ( Main * bmain,
const char * basedir_src,
const char * basedir_dst,
ReportList * reports,
BPathSummary * r_summary = nullptr )

◆ BKE_bpath_summary_report()

void BKE_bpath_summary_report ( const BPathSummary & summary,
ReportList * reports )

◆ bpath_absolute_relative_convert()

static void bpath_absolute_relative_convert ( Main * bmain,
const char * basedir,
ReportList * reports,
BPathForeachPathFunctionCallback callback_function,
BPathSummary * r_summary )
static

◆ bpath_list_append()

static bool bpath_list_append ( BPathForeachPathData * bpath_data,
char * ,
size_t ,
const char * path_src )
static

◆ bpath_list_restore()

static bool bpath_list_restore ( BPathForeachPathData * bpath_data,
char * path_dst,
size_t path_dst_maxncpy,
const char * path_src )
static

◆ check_missing_files_foreach_path_cb()

static bool check_missing_files_foreach_path_cb ( BPathForeachPathData * bpath_data,
char * ,
size_t ,
const char * path_src )
static

◆ missing_files_find__recursive()

static bool missing_files_find__recursive ( const char * search_directory,
const char * filename_src,
char r_filepath_new[FILE_MAX],
int64_t * r_filesize,
int * r_recurse_depth )
static

Find the given filename recursively in the given search directory and its sub-directories.

Note
Use the biggest matching file found, so that thumbnails don't get used by mistake.
Parameters
search_directoryDirectory to search in.
filename_srcSearch for this filename.
r_filepath_newThe path of the new found file will be copied here, caller must initialize as empty string.
r_filesizeSize of the file, FILESIZE_INVALID_DIRECTORY if search directory could not be opened.
r_recurse_depthCurrent recursion depth.
Returns
true if found, false otherwise.

Definition at line 292 of file bpath.cc.

References BLI_path_join, BLI_path_ncmp, BLI_stat(), BLI_strncpy(), CLOG_WARN, closedir(), FILE_MAX, FILENAME_IS_CURRPAR, FILESIZE_INVALID_DIRECTORY, LOG, MAX_DIR_RECURSE, missing_files_find__recursive(), opendir(), readdir(), S_ISDIR, S_ISREG, and size().

Referenced by missing_files_find__recursive(), and missing_files_find_foreach_path_cb().

◆ missing_files_find_foreach_path_cb()

static bool missing_files_find_foreach_path_cb ( BPathForeachPathData * bpath_data,
char * path_dst,
size_t path_dst_maxncpy,
const char * path_src )
static

◆ relative_convert_foreach_path_cb()

static bool relative_convert_foreach_path_cb ( BPathForeachPathData * bpath_data,
char * path_dst,
size_t path_dst_maxncpy,
const char * path_src )
static

◆ relative_rebase_foreach_path_cb()

static bool relative_rebase_foreach_path_cb ( BPathForeachPathData * bpath_data,
char * path_dst,
size_t path_dst_maxncpy,
const char * path_src )
static

Variable Documentation

◆ LOG

CLG_LogRef LOG = {"bke.bpath"}
static

Definition at line 51 of file bpath.cc.

Referenced by bpath_absolute_relative_convert(), and missing_files_find__recursive().