Blender
V3.3
|
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <zlib.h>
#include <zstd.h>
#include <dirent.h>
#include <sys/param.h>
#include <sys/wait.h>
#include <unistd.h>
#include "MEM_guardedalloc.h"
#include "BLI_fileops.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_sys_types.h"
#include "BLI_utildefines.h"
Go to the source code of this file.
Typedefs | |
typedef int(* | RecursiveOp_Callback) (const char *from, const char *to) |
Enumerations | |
enum | { RecursiveOp_Callback_OK = 0 , RecursiveOp_Callback_StopRecurs = 1 , RecursiveOp_Callback_Error = 2 } |
Functions | |
size_t | BLI_file_zstd_from_mem_at_pos (void *buf, size_t len, FILE *file, size_t file_offset, int compression_level) |
size_t | BLI_file_unzstd_to_mem_at_pos (void *buf, size_t len, FILE *file, size_t file_offset) |
bool | BLI_file_magic_is_gzip (const char header[4]) |
bool | BLI_file_magic_is_zstd (const char header[4]) |
bool | BLI_file_is_writable (const char *filepath) |
bool | BLI_file_touch (const char *file) |
static void | join_dirfile_alloc (char **dst, size_t *alloc_len, const char *dir, const char *file) |
static char * | strip_last_slash (const char *dir) |
static int | recursive_operation (const char *startfrom, const char *startto, RecursiveOp_Callback callback_dir_pre, RecursiveOp_Callback callback_file, RecursiveOp_Callback callback_dir_post) |
static int | delete_callback_post (const char *from, const char *UNUSED(to)) |
static int | delete_single_file (const char *from, const char *UNUSED(to)) |
static int | delete_soft (const char *file, const char **error_message) |
FILE * | BLI_fopen (const char *filepath, const char *mode) |
void * | BLI_gzopen (const char *filepath, const char *mode) |
int | BLI_open (const char *filepath, int oflag, int pmode) |
int | BLI_access (const char *filepath, int mode) |
int | BLI_delete (const char *file, bool dir, bool recursive) |
int | BLI_delete_soft (const char *file, const char **error_message) |
static bool | check_the_same (const char *path_a, const char *path_b) |
static int | set_permissions (const char *file, const struct stat *st) |
static int | copy_callback_pre (const char *from, const char *to) |
static int | copy_single_file (const char *from, const char *to) |
static const char * | check_destination (const char *file, const char *to) |
int | BLI_copy (const char *file, const char *to) |
bool | BLI_dir_create_recursive (const char *dirname) |
int | BLI_rename (const char *from, const char *to) |
typedef int(* RecursiveOp_Callback) (const char *from, const char *to) |
anonymous enum |
int BLI_access | ( | const char * | filepath, |
int | mode | ||
) |
Definition at line 927 of file fileops.c.
References BLI_assert, and BLI_path_is_rel().
Referenced by bli_builddir(), BLI_file_is_writable(), BLI_path_parent_dir_until_exists(), seq_proxy_multiview_context_invalid(), wm_homefile_read_ex(), and wm_homefile_read_exec().
int BLI_copy | ( | const char * | file, |
const char * | to | ||
) |
Definition at line 1198 of file fileops.c.
References check_destination(), copy_callback_pre(), copy_single_file(), file, MEM_freeN, NULL, recursive_operation(), and ret.
Referenced by BKE_packedfile_compare_to_file(), blender::io::usd::copy_single_file(), blender::io::usd::copy_tiled_textures(), DocumentExporter::exportCurrentScene(), blender::io::path_reference_copy(), blender::bke::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), and blender::bke::tests::TEST_F().
Deletes the specified file or directory (depending on dir), optionally doing recursive delete of directory contents.
Definition at line 934 of file fileops.c.
References BLI_assert, BLI_path_is_rel(), delete_callback_post(), delete_single_file(), file, NULL, recursive_operation(), and blender::bke::attribute_accessor_functions::remove().
Referenced by BKE_packedfile_compare_to_file(), BKE_ptcache_id_clear(), BKE_tempdir_session_purge(), BLI_rename(), cdf_remove(), blender::io::obj::obj_mtl_parser_test::check_string(), blender::io::obj::obj_exporter_regression_test::compare_obj_export_to_golden(), blender::compositor::DebugInfo::delete_operation_exports(), blender::io::alembic::AlembicExportTest::deleteArchive(), blender::io::alembic::export_endjob(), blender::io::usd::export_endjob(), DocumentExporter::exportCurrentScene(), IMB_thumb_delete(), IMB_thumb_manage(), RE_RenderAnim(), blender::ed::asset::index::AssetLibraryIndex::remove_unused_index_files(), seq_disk_cache_delete_file(), seq_disk_cache_handle_versioning(), blender::bke::tests::AssetCatalogTest::TearDown(), blender::bke::tests::AssetLibraryServiceTest::TearDown(), and wm_autosave_delete().
int BLI_delete_soft | ( | const char * | file, |
const char ** | error_message | ||
) |
Soft deletes the specified file or directory (depending on dir) by moving the files to the recycling bin, optionally doing recursive delete of directory contents.
Definition at line 947 of file fileops.c.
References BLI_assert, BLI_path_is_rel(), delete_soft(), and file.
Referenced by file_delete_single().
bool BLI_dir_create_recursive | ( | const char * | dir | ) |
Definition at line 1219 of file fileops.c.
References BLI_dir_create_recursive(), BLI_exists(), BLI_is_dir(), BLI_path_slash_rfind(), BLI_path_slash_rstrip(), BLI_strncpy(), dirname(), MAXPATHLEN, MEM_callocN, MEM_freeN, ret, and size().
Referenced by BKE_appdir_folder_id_create(), BLI_dir_create_recursive(), BLI_make_existing_file(), blender::bke::tests::AssetCatalogTest::create_temp_path(), blender::bke::tests::AssetLibraryServiceTest::create_temp_path(), blender::bke::AssetCatalogDefinitionFile::ensure_directory_exists(), blender::io::usd::export_texture(), MANTA::exportLiquidScript(), MANTA::exportSmokeScript(), file_directory_new_exec(), fluid_bake_startjob(), fluid_validatepaths(), IMB_thumb_makedirs(), blender::bke::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), tempdir_session_create(), blender::bke::tests::TEST_F(), and MANTA::writeConfiguration().
bool BLI_file_is_writable | ( | const char * | filepath | ) |
Returns true if the file with the specified name can be written. This implementation uses access(2), which makes the check according to the real UID and GID of the process, not its effective UID and GID. This shouldn't matter for Blender, which is not going to run privileged anyway.
Definition at line 167 of file fileops.c.
References BLI_access(), BLI_split_dirfile(), FILE_MAX, and NULL.
Referenced by image_save_exec(), sequencer_export_subtitles_exec(), txt_write_file(), and wm_file_write().
bool BLI_file_magic_is_gzip | ( | const char | header[4] | ) |
Definition at line 133 of file fileops.c.
Referenced by blendthumb_create_thumb_from_file(), blo_filedata_from_file_descriptor(), blo_filedata_from_memory(), and wm_read_exotic().
bool BLI_file_magic_is_zstd | ( | const char | header[4] | ) |
Definition at line 140 of file fileops.c.
References magic().
Referenced by blendthumb_create_thumb_from_file(), blo_filedata_from_file_descriptor(), blo_filedata_from_memory(), inflate_file_to_imbuf(), and wm_read_exotic().
bool BLI_file_touch | ( | const char * | file | ) |
Creates the file with nothing in it, or updates its last-modified date if it already exists. Returns true if successful (like the unix touch command).
Definition at line 192 of file fileops.c.
References BLI_fopen(), Freestyle::c, file, and NULL.
Referenced by RE_RenderAnim(), blender::bke::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), seq_disk_cache_read_file(), and sequencer_export_subtitles_exec().
size_t BLI_file_unzstd_to_mem_at_pos | ( | void * | buf, |
size_t | len, | ||
FILE * | file, | ||
size_t | file_offset | ||
) |
Definition at line 96 of file fileops.c.
References file, input, len, MEM_freeN, MEM_mallocN, output, and ret.
Referenced by inflate_file_to_imbuf().
size_t BLI_file_zstd_from_mem_at_pos | ( | void * | buf, |
size_t | len, | ||
FILE * | file, | ||
size_t | file_offset, | ||
int | compression_level | ||
) |
Definition at line 49 of file fileops.c.
References file, input, len, MEM_freeN, MEM_mallocN, output, and ret.
Referenced by deflate_imbuf_to_file().
FILE* BLI_fopen | ( | const char * | filepath, |
const char * | mode | ||
) |
Definition at line 906 of file fileops.c.
References BLI_assert, and BLI_path_is_rel().
Referenced by arg_handle_log_file_set(), AVI_is_avi(), AVI_open_compress(), AVI_open_movie(), BKE_report_write_file(), BLI_file_read_as_lines(), BLI_file_read_binary_as_mem(), BLI_file_read_text_as_mem(), BLI_file_touch(), cdf_read_open(), cdf_write_open(), blender::io::obj::obj_mtl_parser_test::check_string(), cineonCreate(), cineonOpen(), dpxCreate(), dpxOpen(), EEVEE_lut_update_ggx_brdf(), EEVEE_lut_update_ggx_btdf(), fsmenu_read_bookmarks(), fsmenu_write_file(), fsmenu_xdg_user_dirs_parse(), blender::compositor::DebugInfo::graphviz(), IMB_index_builder_create(), IMB_indexer_open(), imb_savebmp(), imb_savehdr(), imb_savepng(), imb_savetarga(), imb_savewebp(), imb_thumbnail_jpeg(), blender::io::stl::importer_main(), logImageOpenFromFile(), make(), MOD_meshcache_read_mdd_times(), MOD_meshcache_read_pc2_times(), blender::io::obj::MTLWriter::MTLWriter(), blender::io::obj::OBJParser::OBJParser(), blender::io::obj::OBJWriter::OBJWriter(), opj_stream_create_from_file(), output_iris(), ptcache_file_open(), python_script_exec(), save_stdjpeg(), seq_disk_cache_create_version_file(), seq_disk_cache_handle_versioning(), seq_disk_cache_read_file(), seq_disk_cache_write_file(), sequencer_export_subtitles_exec(), sig_handle_crash(), studiolight_calculate_diffuse_light(), studiolight_load_spherical_harmonics_coefficients(), studiolight_write_solid_light(), txt_write_file(), wm_history_file_write(), and wm_platform_support_check_approval().
void* BLI_gzopen | ( | const char * | filepath, |
const char * | mode | ||
) |
Definition at line 913 of file fileops.c.
References BLI_assert, and BLI_path_is_rel().
Referenced by MANTA::readConfiguration(), and MANTA::writeConfiguration().
int BLI_open | ( | const char * | filepath, |
int | oflag, | ||
int | pmode | ||
) |
Definition at line 920 of file fileops.c.
References BLI_assert, BLI_path_is_rel(), and oflag.
Referenced by BKE_image_load(), BKE_movieclip_file_add(), BKE_packedfile_compare_to_file(), BKE_packedfile_new(), blo_filedata_from_file_open(), BLO_memfile_write_file(), build_pict_list_ex(), extract_png_from_blend_file(), image_update_views_format(), imb_ispic_read_header_from_filepath(), IMB_loadiffname(), imb_loadtile(), IMB_testiffname(), IMMapStream::IMMapStream(), M_imbuf_load(), prefetch_read_file_to_memory(), proxy_thread_next_frame(), wm_read_exotic(), and ww_open_none().
int BLI_rename | ( | const char * | from, |
const char * | to | ||
) |
Definition at line 1268 of file fileops.c.
References BLI_delete(), BLI_exists(), and from.
Referenced by BKE_packedfile_compare_to_file(), BKE_ptcache_disk_cache_rename(), BLO_write_file(), do_history(), DocumentExporter::exportCurrentScene(), IMB_index_builder_finish(), renamebutton_cb(), thumb_create_ex(), wm_autosave_delete(), and blender::bke::AssetCatalogDefinitionFile::write_to_disk().
|
static |
Definition at line 1164 of file fileops.c.
References BLI_join_dirfile(), BLI_path_slash_rfind(), file, len, MEM_callocN, MEM_freeN, S_ISDIR, usdtokens::st(), str, and strip_last_slash().
Referenced by BLI_copy().
|
static |
Do the two paths denote the same file-system object?
Definition at line 957 of file fileops.c.
Referenced by copy_callback_pre(), and copy_single_file().
|
static |
Definition at line 992 of file fileops.c.
References check_the_same(), from, RecursiveOp_Callback_Error, RecursiveOp_Callback_OK, and usdtokens::st().
Referenced by BLI_copy().
|
static |
Definition at line 1021 of file fileops.c.
References check_the_same(), from, len, MEM_callocN, MEM_freeN, RecursiveOp_Callback_Error, RecursiveOp_Callback_OK, S_ISREG, set_permissions(), and usdtokens::st().
Referenced by BLI_copy().
|
static |
Definition at line 790 of file fileops.c.
References from, RecursiveOp_Callback_Error, and RecursiveOp_Callback_OK.
Referenced by BLI_delete().
|
static |
Definition at line 801 of file fileops.c.
References from, RecursiveOp_Callback_Error, and RecursiveOp_Callback_OK.
Referenced by BLI_delete().
|
static |
|
static |
Definition at line 617 of file fileops.c.
References BLI_join_dirfile(), file, len, MEM_mallocN, MEM_reallocN, and NULL.
Referenced by recursive_operation().
|
static |
Scans startfrom, generating a corresponding destination name for each item found by prefixing it with startto, recursively scanning subdirectories, and invoking the specified callbacks for files and subdirectories found as appropriate.
startfrom | Top-level source path. |
startto | Top-level destination path. |
callback_dir_pre | Optional, to be invoked before entering a subdirectory, can return RecursiveOp_Callback_StopRecurs to skip the subdirectory. |
callback_file | Optional, to be invoked on each file found. |
callback_dir_post | optional, to be invoked after leaving a subdirectory. |
Definition at line 654 of file fileops.c.
References BLI_path_join(), dirent::d_name, FILE_MAX, FILENAME_IS_CURRPAR, free(), from, join_dirfile_alloc(), MEM_freeN, NULL, RecursiveOp_Callback_OK, RecursiveOp_Callback_StopRecurs, ret, S_ISDIR, usdtokens::st(), and strip_last_slash().
Referenced by BLI_copy(), and BLI_delete().
|
static |
Sets the mode and ownership of file to the values from st.
Definition at line 975 of file fileops.c.
References file, and usdtokens::st().
Referenced by copy_single_file().
|
static |
Definition at line 633 of file fileops.c.
References BLI_path_slash_rstrip(), BLI_strdup(), and result.
Referenced by check_destination(), and recursive_operation().