|
Blender V5.0
|
#include <algorithm>#include <cstdlib>#include <cstring>#include <fcntl.h>#include <sys/stat.h>#include <sys/types.h>#include <cerrno>#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_utils.hh"#include "BLI_string.h"#include "BLI_sys_types.h"#include "BLI_utildefines.h"Go to the source code of this file.
Classes | |
| struct | StrBuf |
Macros | |
| #define | FILE_MAX_STATIC_BUF 256 |
Typedefs | |
| using | RecursiveOp_Callback = int (*)(const char *from, const char *to) |
Enumerations | |
| enum | { RecursiveOp_Callback_OK = 0 , RecursiveOp_Callback_StopRecurs = 1 , RecursiveOp_Callback_Error = 2 } |
Functions | |
| int64_t | BLI_read (int fd, void *buf, size_t nbytes) |
| bool | BLI_file_external_operation_supported (const char *filepath, FileExternalOperation operation) |
| bool | BLI_file_external_operation_execute (const char *filepath, FileExternalOperation operation) |
| 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 *filepath) |
| static bool | dir_create_recursive (const char *dirname, const int len) |
| bool | BLI_dir_create_recursive (const char *dirname) |
| bool | BLI_file_ensure_parent_dir_exists (const char *filepath) |
| int | BLI_rename (const char *from, const char *to) |
| int | BLI_rename_overwrite (const char *from, const char *to) |
| static bool | path_has_trailing_slash (const char *path) |
| static size_t | path_len_no_trailing_slash (const char *path) |
| static int | recursive_operation_impl (StrBuf *src_buf, StrBuf *dst_buf, RecursiveOp_Callback callback_dir_pre, RecursiveOp_Callback callback_file, RecursiveOp_Callback callback_dir_post) |
| static int | recursive_operation (const char *path_src, const char *path_dst, RecursiveOp_Callback callback_dir_pre, RecursiveOp_Callback callback_file, RecursiveOp_Callback callback_dir_post) |
| static int | delete_callback_post (const char *from, const char *) |
| static int | delete_single_file (const char *from, const char *) |
| 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 *path, bool dir, bool recursive) |
| int | BLI_delete_soft (const char *filepath, const char **r_error_message) |
| static bool | check_the_same (const char *path_a, const char *path_b) |
| static int | set_permissions (const char *filepath, 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 int | move_callback_pre (const char *from, const char *to) |
| static int | move_single_file (const char *from, const char *to) |
| int | BLI_path_move (const char *path_src, const char *path_dst) |
| static const char * | path_destination_ensure_filename (const char *path_src, const char *path_dst, char *buf, size_t buf_size) |
| int | BLI_copy (const char *path_src, const char *path_dst) |
Simple String Buffer | |
| static void | strbuf_init (StrBuf *buf, const char *str, size_t str_len, size_t str_len_alloc) |
| static void | strbuf_free (StrBuf *buf) |
| static void | strbuf_append_path (StrBuf *buf, const char *filename) |
| static void | strbuf_trim (StrBuf *buf, size_t len) |
| #define FILE_MAX_STATIC_BUF 256 |
Sizes above this must be allocated.
Definition at line 53 of file fileops_c.cc.
Referenced by BLI_copy().
| using RecursiveOp_Callback = int (*)(const char *from, const char *to) |
Definition at line 895 of file fileops_c.cc.
| anonymous enum |
| Enumerator | |
|---|---|
| RecursiveOp_Callback_OK | |
| RecursiveOp_Callback_StopRecurs | |
| RecursiveOp_Callback_Error | |
Definition at line 884 of file fileops_c.cc.
| int BLI_access | ( | const char * | filepath, |
| int | mode ) |
Definition at line 1204 of file fileops_c.cc.
References BLI_assert, and BLI_path_is_rel().
Referenced by bli_builddir(), BLI_file_is_writable(), BLI_path_parent_dir_until_exists(), blender::seq::seq_proxy_multiview_context_invalid(), wm_homefile_read_ex(), and wm_homefile_read_exec().
| int BLI_copy | ( | const char * | path_src, |
| const char * | path_dst ) |
Definition at line 1546 of file fileops_c.cc.
References copy_callback_pre(), copy_single_file(), ELEM, FILE_MAX_STATIC_BUF, MEM_freeN(), path_destination_ensure_filename(), recursive_operation(), and ret.
Referenced by BKE_packedfile_write_to_file(), blender::io::usd::copy_single_file(), blender::io::usd::copy_tiled_textures(), blender::io::path_reference_copy(), blender::asset_system::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), and blender::io::usd::world_material_to_dome_light().
| int BLI_delete | ( | const char * | path, |
| bool | dir, | ||
| bool | recursive ) |
Deletes the specified file or directory.
| dir | Delete an empty directory instead of a file. The value is ignored when recursive is true but should true to make the intention clear. If the directory is not empty, delete fails. |
| recursive | Recursively delete files including path which may be a directory of a file. |
Definition at line 1211 of file fileops_c.cc.
References BLI_assert, BLI_path_is_rel(), delete_callback_post(), delete_single_file(), and recursive_operation().
Referenced by blender::bke::asset_edit_id_delete(), BKE_packedfile_write_to_file(), BKE_ptcache_id_clear(), BKE_tempdir_session_purge(), BLI_rename_overwrite(), blender::gpu::VKShaderCompiler::cache_dir_clear_old(), cdf_remove(), blender::io::obj::OBJMTLParserTest::check_string(), blender::io::obj::OBJExportRegressionTest::compare_obj_export_to_golden(), blender::io::stl::STLExportTest::compare_to_golden(), blender::ed::asset::index::AssetLibraryIndex::delete_file_index(), blender::io::alembic::AlembicExportTest::deleteArchive(), blender::io::alembic::export_endjob(), blender::io::usd::export_endjob(), blender::io::usd::export_endjob_usdz_cleanup(), IMB_thumb_delete(), IMB_thumb_manage(), blender::io::usd::load_image(), blender::io::usd::USDMaterialReader::load_tex_image(), blender::io::usd::perform_usdz_conversion(), blender::io::hydra::USDSceneDelegate::populate(), preferences_extension_repo_remove_exec(), RE_RenderAnim(), blender::asset_system::tests::AssetLibraryServiceTest::TearDown(), blender::asset_system::tests::AssetLibraryTestBase::TearDown(), blender::io::usd::UsdExportTest::TearDown(), blender::tests::ChangeWorkingDirectoryTest::TearDown(), blender::tests::FileOpsTest::TearDown(), blender::tests::TEST_F(), blender::ed::object::bake_simulation::try_delete_bake(), blender::bke::bake::unpack_geometry_nodes_bake(), wm_autosave_delete(), and blender::io::hydra::USDSceneDelegate::~USDSceneDelegate().
| int BLI_delete_soft | ( | const char * | filepath, |
| const char ** | r_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 1228 of file fileops_c.cc.
References BLI_assert, BLI_assert_unreachable, BLI_path_is_rel(), BLI_string_elem_split_by_delim(), error(), result, STREQ, and UNLIKELY.
Referenced by file_delete_single().
| bool BLI_dir_create_recursive | ( | const char * | dirname | ) |
Definition at line 414 of file fileops_c.cc.
References BLI_assert, BLI_exists(), BLI_path_slash_is_native_compat(), dir_create_recursive(), dirname(), FILE_MAX, len, MEM_calloc_arrayN(), MEM_freeN(), ret, S_ISDIR, and true.
Referenced by blender::bke::asset_blendfile_path_for_save(), BKE_appdir_folder_id_create(), BLI_file_ensure_parent_dir_exists(), blender::gpu::cache_dir_get(), blender::asset_system::tests::AssetLibraryServiceTest::create_temp_path(), blender::asset_system::tests::AssetLibraryTestBase::create_temp_path(), blender::asset_system::AssetCatalogDefinitionFile::ensure_directory_exists(), MANTA::exportLiquidScript(), MANTA::exportSmokeScript(), file_directory_new_exec(), fluid_bake_startjob(), fluid_validatepaths(), blender::io::usd::get_export_textures_dir(), blender::io::usd::get_image_cache_file(), IMB_thumb_makedirs(), blender::io::usd::import_asset(), blender::io::hydra::USDSceneDelegate::populate(), blender::asset_system::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), blender::tests::FileOpsTest::SetUp(), tempdir_session_create(), blender::asset_system::tests::TEST_F(), blender::tests::TEST_F(), blender::tests::TEST_F(), blender::tests::TEST_F(), blender::io::hydra::USDSceneDelegate::USDSceneDelegate(), blender::io::usd::world_material_to_dome_light(), and MANTA::writeConfiguration().
| bool BLI_file_ensure_parent_dir_exists | ( | const char * | filepath | ) |
Ensures that the parent directory of filepath exists.
Definition at line 452 of file fileops_c.cc.
References BLI_dir_create_recursive(), BLI_path_split_dir_part(), and FILE_MAX.
Referenced by blender::ed::object::bake_simulation::bake_geometry_nodes_startjob(), BKE_image_render_write_exr(), BKE_imbuf_write(), BKE_packedfile_write_to_file(), dynamicPaint_outputSurfaceImage(), blender::ed::asset::index::AssetIndexFile::ensure_parent_path_exists(), movieclip_build_proxy_ibuf(), blender::io::path_reference_copy(), ptcache_file_open(), blender::seq::seq_proxy_build_frame(), blender::ed::vse::sequencer_export_subtitles_exec(), touch_file(), blender::bke::bake::unpack_bake_to_disk(), blender::bke::bake::DiskBlobWriter::write(), and blender::bke::bake::DiskBlobWriter::write_as_stream().
| bool BLI_file_external_operation_execute | ( | const char * | filepath, |
| FileExternalOperation | operation ) |
Definition at line 157 of file fileops_c.cc.
References BLI_windows_external_operation_execute(), BLI_windows_external_operation_supported(), and UNUSED_VARS.
Referenced by file_external_operation_exec().
| bool BLI_file_external_operation_supported | ( | const char * | filepath, |
| FileExternalOperation | operation ) |
Definition at line 146 of file fileops_c.cc.
References BLI_windows_external_operation_supported(), and UNUSED_VARS.
Referenced by file_os_operations_menu_item().
| 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 291 of file fileops_c.cc.
References BLI_access(), BLI_path_split_dir_part(), and FILE_MAX.
Referenced by blender::bke::asset_link_id(), image_save_exec(), blender::ed::vse::sequencer_export_subtitles_exec(), txt_write_file(), and wm_file_write().
| bool BLI_file_magic_is_gzip | ( | const char | header[4] | ) |
Definition at line 257 of file fileops_c.cc.
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 264 of file fileops_c.cc.
References magic().
Referenced by blendthumb_create_thumb_from_file(), blo_filedata_from_file_descriptor(), blo_filedata_from_memory(), and wm_read_exotic().
| bool BLI_file_touch | ( | const char * | filepath | ) |
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 316 of file fileops_c.cc.
References BLI_fopen().
Referenced by blender::gpu::VKPipelinePool::read_from_disk(), blender::gpu::read_spirv_from_disk(), blender::asset_system::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), blender::ed::vse::sequencer_export_subtitles_exec(), blender::tests::TEST_F(), blender::tests::TEST_F(), and touch_file().
| size_t BLI_file_unzstd_to_mem_at_pos | ( | void * | buf, |
| size_t | len, | ||
| FILE * | file, | ||
| size_t | file_offset ) |
Definition at line 220 of file fileops_c.cc.
References input, len, MEM_freeN(), MEM_mallocN(), output, and ret.
| 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 173 of file fileops_c.cc.
References input, len, MEM_freeN(), MEM_mallocN(), output, and ret.
| FILE * BLI_fopen | ( | const char * | filepath, |
| const char * | mode ) |
Definition at line 1183 of file fileops_c.cc.
References BLI_assert, and BLI_path_is_rel().
Referenced by arg_handle_log_file_set(), 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::OBJMTLParserTest::check_string(), cineonCreate(), cineonOpen(), crashlog_file_generate(), dpxCreate(), dpxOpen(), blender::io::fbx::FbxImportContext::FbxImportContext(), blender::io::ply::FileBuffer::FileBuffer(), blender::io::stl::FileWriter::FileWriter(), fsmenu_read_bookmarks(), fsmenu_write_file(), fsmenu_xdg_user_dirs_parse(), imb_savewebp(), imb_thumbnail_jpeg(), blender::io::fbx::importer_main(), logImageOpenFromFile(), make(), MOD_meshcache_read_mdd_times(), MOD_meshcache_read_pc2_times(), blender::locale::MOFile::MOFile(), movie_index_open(), blender::io::obj::MTLWriter::MTLWriter(), blender::io::obj::OBJParser::OBJParser(), blender::io::obj::OBJWriter::OBJWriter(), opj_stream_create_from_file(), output_iris(), blender::io::ply::PlyReadBuffer::PlyReadBuffer(), ptcache_file_open(), python_script_exec(), blender::io::stl::read_stl_file(), save_stdjpeg(), blender::ed::vse::sequencer_export_subtitles_exec(), 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 1190 of file fileops_c.cc.
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 1197 of file fileops_c.cc.
References BLI_assert, BLI_path_is_rel(), and oflag.
Referenced by BKE_image_load_in_lib(), BKE_movieclip_file_add(), BKE_packedfile_compare_to_file(), BKE_packedfile_new(), BKE_packedfile_write_to_file(), blo_filedata_from_file_open(), buffer_from_filepath(), blender::bke::id_hash::compute_file_hash_with_memory_map(), extract_png_from_blend_file(), FileDescriptorRAII::FileDescriptorRAII(), image_update_views_format(), imb_load_filepath_thumbnail_webp(), IMB_load_image_from_filepath(), imb_test_image_read_header_from_filepath(), imbuf_load_impl(), IMMapStream::IMMapStream(), RawWriteWrap::open(), prefetch_read_file_to_memory(), proxy_thread_next_frame(), blender::tests::TEST_F(), and wm_read_exotic().
| int BLI_path_move | ( | const char * | path_src, |
| const char * | path_dst ) |
When path_src points to a directory, moves all its contents into path_dst, else rename path_src itself to path_dst.
Definition at line 1512 of file fileops_c.cc.
References delete_callback_post(), delete_single_file(), move_callback_pre(), move_single_file(), recursive_operation(), and ret.
Referenced by blender::io::usd::perform_usdz_conversion().
| int64_t BLI_read | ( | int | fd, |
| void * | buf, | ||
| size_t | nbytes ) |
A version of read with the following differences:
Definition at line 96 of file fileops_c.cc.
References BLI_assert_unreachable, read, and UNLIKELY.
Referenced by BKE_packedfile_compare_to_file(), BKE_packedfile_new(), buffer_from_filepath(), file_read(), imb_test_image_read_header_from_filepath(), prefetch_read_file_to_memory(), and proxy_thread_next_frame().
| int BLI_rename | ( | const char * | from, |
| const char * | to ) |
Rename a file or directory, unless to already exists.
| from | The path to rename from (return failure if it does not exist). |
| to | The destination path. |
Definition at line 461 of file fileops_c.cc.
References BLI_exists(), ret, and urename().
Referenced by renamebutton_cb(), and blender::tests::TEST_F().
| int BLI_rename_overwrite | ( | const char * | from, |
| const char * | to ) |
Rename a file or directory, replacing target to path if it exists.
See BLI_path_move to move directories.
| from | The path to rename from (return failure if it does not exist). |
| to | The destination path. This will be deleted if it already exists, unless it's a directory which will fail. |
Definition at line 528 of file fileops_c.cc.
References BLI_delete(), BLI_exists(), BLI_is_dir(), and urename().
Referenced by BKE_packedfile_write_to_file(), BKE_ptcache_disk_cache_rename(), BLO_write_file_impl(), do_history(), blender::tests::TEST_F(), thumb_create_ex(), wm_autosave_delete(), and blender::asset_system::AssetCatalogDefinitionFile::write_to_disk().
|
static |
Do the two paths denote the same file-system object?
Definition at line 1321 of file fileops_c.cc.
Referenced by copy_callback_pre(), and copy_single_file().
|
static |
Definition at line 1356 of file fileops_c.cc.
References check_the_same(), RecursiveOp_Callback_Error, and RecursiveOp_Callback_OK.
Referenced by BLI_copy(), and move_callback_pre().
|
static |
Definition at line 1385 of file fileops_c.cc.
References check_the_same(), len, MEM_calloc_arrayN(), MEM_freeN(), RecursiveOp_Callback_Error, RecursiveOp_Callback_OK, S_ISREG, and set_permissions().
Referenced by BLI_copy(), and move_single_file().
|
static |
Definition at line 1161 of file fileops_c.cc.
References RecursiveOp_Callback_Error, and RecursiveOp_Callback_OK.
Referenced by BLI_delete(), and BLI_path_move().
|
static |
Definition at line 1172 of file fileops_c.cc.
References RecursiveOp_Callback_Error, and RecursiveOp_Callback_OK.
Referenced by BLI_delete(), and BLI_path_move().
|
static |
Create the given directory and its parents if necessary.
If the directory already exists, this function is a no-op.
| dirname | The directory to create. |
| len | The number of bytes of dirname to use as path to create. This makes the recursive call possible without doing string duplication for each parent directory. |
Definition at line 354 of file fileops_c.cc.
References BLI_assert, BLI_assert_msg, BLI_exists(), BLI_is_dir(), BLI_path_is_win32_drive_only(), BLI_path_parent_dir_end(), BLI_path_slash_is_native_compat(), dir_create_recursive(), dirname(), len, ret, S_ISDIR, STREQ, and umkdir().
Referenced by BLI_dir_create_recursive(), dir_create_recursive(), and blender::tests::TEST_F().
|
static |
Definition at line 1490 of file fileops_c.cc.
References copy_callback_pre(), RecursiveOp_Callback_StopRecurs, and ret.
Referenced by BLI_path_move().
|
static |
Definition at line 1501 of file fileops_c.cc.
References copy_single_file(), RecursiveOp_Callback_OK, and ret.
Referenced by BLI_path_move().
|
static |
Definition at line 1524 of file fileops_c.cc.
References BLI_is_dir(), BLI_path_basename(), BLI_path_join, BLI_path_slash_rstrip(), BLI_strdup(), MEM_calloc_arrayN(), and MEM_freeN().
Referenced by BLI_copy().
|
static |
Definition at line 897 of file fileops_c.cc.
References BLI_path_slash_is_native_compat(), and direntry::path.
Referenced by recursive_operation_impl(), and strbuf_append_path().
|
static |
Definition at line 906 of file fileops_c.cc.
References BLI_path_slash_is_native_compat(), len, and direntry::path.
Referenced by recursive_operation().
|
static |
Scans path_src, generating a corresponding destination name for each item found by prefixing it with path_dst, recursively scanning subdirectories, and invoking the specified callbacks for files and subdirectories found as appropriate.
| path_src | Top-level source path. |
| path_dst | 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 1128 of file fileops_c.cc.
References FILE_MAX, path_len_no_trailing_slash(), recursive_operation_impl(), result, strbuf_free(), and strbuf_init().
Referenced by BLI_copy(), BLI_delete(), and BLI_path_move().
|
static |
Definition at line 981 of file fileops_c.cc.
References BLI_assert, dirent::d_name, FILENAME_IS_CURRPAR, free(), i, path_has_trailing_slash(), recursive_operation_impl(), RecursiveOp_Callback_OK, RecursiveOp_Callback_StopRecurs, ret, S_ISDIR, StrBuf::str, StrBuf::str_len, strbuf_append_path(), and strbuf_trim().
Referenced by recursive_operation(), and recursive_operation_impl().
|
static |
Sets the mode and ownership of file to the values from st.
Definition at line 1339 of file fileops_c.cc.
Referenced by copy_single_file().
|
static |
Appending of filename to dir (ensures for buffer size before appending).
Definition at line 951 of file fileops_c.cc.
References BLI_assert, BLI_path_slash_is_native_compat(), len, path_has_trailing_slash(), SEP, StrBuf::str, StrBuf::str_len, and StrBuf::str_len_alloc.
Referenced by recursive_operation_impl().
|
static |
Definition at line 943 of file fileops_c.cc.
References free(), and StrBuf::str.
Referenced by recursive_operation().
|
static |
Definition at line 933 of file fileops_c.cc.
References str, StrBuf::str, StrBuf::str_len, and StrBuf::str_len_alloc.
Referenced by recursive_operation().
|
static |
Definition at line 972 of file fileops_c.cc.
References BLI_assert, len, StrBuf::str, and StrBuf::str_len.
Referenced by recursive_operation_impl().