|
Blender V4.3
|
#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_string_utils.hh"#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 | |
| 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 | |
| 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 (char *dirname, 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().
| typedef int(* RecursiveOp_Callback) (const char *from, const char *to) |
Definition at line 873 of file fileops_c.cc.
| anonymous enum |
| Enumerator | |
|---|---|
| RecursiveOp_Callback_OK | |
| RecursiveOp_Callback_StopRecurs | |
| RecursiveOp_Callback_Error | |
Definition at line 862 of file fileops_c.cc.
Definition at line 1182 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(), 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 1519 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(), DocumentExporter::exportCurrentScene(), 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. |
path itself links to another directory, deleting path behaves as if a regular file is being deleted.dir is true and path is a link, delete fails.Definition at line 1189 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::compositor::DebugInfo::delete_operation_exports(), blender::io::alembic::AlembicExportTest::deleteArchive(), blender::io::alembic::export_endjob(), blender::io::usd::export_endjob(), blender::io::usd::export_endjob_usdz_cleanup(), DocumentExporter::exportCurrentScene(), 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(), seq_disk_cache_delete_file(), seq_disk_cache_handle_versioning(), blender::asset_system::tests::AssetLibraryServiceTest::TearDown(), blender::asset_system::tests::AssetLibraryTestBase::TearDown(), blender::io::usd::UsdCurvesTest::TearDown(), blender::io::usd::UsdExportTest::TearDown(), blender::io::usd::UsdUsdzExportTest::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 1206 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 391 of file fileops_c.cc.
References BLI_assert, BLI_exists(), BLI_path_slash_is_native_compat(), dir_create_recursive(), dirname(), FILE_MAX, len, 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(), blender::io::usd::export_texture(), 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::io::usd::UsdUsdzExportTest::SetUp(), blender::tests::FileOpsTest::SetUp(), tempdir_session_create(), blender::asset_system::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 429 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(), blender::compositor::DebugInfo::export_operation(), IMB_index_builder_create(), movieclip_build_proxy_ibuf(), blender::io::path_reference_copy(), ptcache_file_open(), RE_RenderAnim(), seq_disk_cache_create_version_file(), seq_disk_cache_read_file(), seq_disk_cache_write_file(), seq_proxy_build_frame(), sequencer_export_subtitles_exec(), 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(), 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(), inflate_file_to_imbuf(), 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 RE_RenderAnim(), blender::gpu::VKPipelinePool::read_from_disk(), blender::gpu::read_spirv_from_disk(), blender::asset_system::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), seq_disk_cache_read_file(), sequencer_export_subtitles_exec(), and blender::tests::TEST_F().
| 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 len, MEM_freeN(), MEM_mallocN, 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 173 of file fileops_c.cc.
References len, MEM_freeN(), MEM_mallocN, and ret.
Referenced by deflate_imbuf_to_file().
| FILE * BLI_fopen | ( | const char * | filepath, |
| const char * | mode ) |
Definition at line 1161 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(), dpxCreate(), dpxOpen(), blender::io::ply::FileBuffer::FileBuffer(), blender::io::stl::FileWriter::FileWriter(), fsmenu_read_bookmarks(), fsmenu_write_file(), fsmenu_xdg_user_dirs_parse(), blender::compositor::DebugInfo::graphviz(), IMB_index_builder_create(), IMB_indexer_open(), imb_savewebp(), imb_thumbnail_jpeg(), 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(), blender::io::ply::PlyReadBuffer::PlyReadBuffer(), ptcache_file_open(), python_script_exec(), blender::io::stl::read_stl_file(), 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_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 1168 of file fileops_c.cc.
References BLI_assert, and BLI_path_is_rel().
Referenced by MANTA::readConfiguration(), and MANTA::writeConfiguration().
Definition at line 1175 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(), extract_png_from_blend_file(), image_update_views_format(), imb_ispic_read_header_from_filepath(), imb_load_filepath_thumbnail_webp(), IMB_loadiffname(), IMB_testiffname(), 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 1485 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().
A version of read with the following differences:
size_t bytes instead of int on WIN32. Definition at line 96 of file fileops_c.cc.
References BLI_assert_unreachable, and UNLIKELY.
Referenced by BKE_packedfile_compare_to_file(), BKE_packedfile_new(), buffer_from_filepath(), file_read(), imb_ispic_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.
rename logic, not Unix one. It does not allow to replace an existing target. Use BLI_rename_overwrite instead if existing file should be replaced.| from | The path to rename from (return failure if it does not exist). |
| to | The destination path. |
Definition at line 438 of file fileops_c.cc.
References BLI_exists(), ret, and urename().
Referenced by IMB_index_builder_finish(), 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.
rename logic. It does allow to replace an existing target. Use BLI_rename instead if existing file should never be replaced. However, if to is an existing, non-empty directory, the operation will fail.to exists and is opened by some process in the system:from and to are not the same directory. Since to is being deleted to make room for from, this will result in from being deleted as well.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 505 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(), DocumentExporter::exportCurrentScene(), 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 1294 of file fileops_c.cc.
Referenced by copy_callback_pre(), and copy_single_file().
|
static |
Definition at line 1329 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 1358 of file fileops_c.cc.
References check_the_same(), len, 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 1139 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 1150 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 344 of file fileops_c.cc.
References BLI_assert, BLI_assert_msg, BLI_exists(), 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(), and dir_create_recursive().
|
static |
Definition at line 1463 of file fileops_c.cc.
References copy_callback_pre(), RecursiveOp_Callback_StopRecurs, and ret.
Referenced by BLI_path_move().
|
static |
Definition at line 1474 of file fileops_c.cc.
References copy_single_file(), RecursiveOp_Callback_OK, and ret.
Referenced by BLI_path_move().
|
static |
Definition at line 1497 of file fileops_c.cc.
References BLI_is_dir(), BLI_path_basename(), BLI_path_join, BLI_path_slash_rstrip(), BLI_strdup(), and MEM_freeN().
Referenced by BLI_copy().
|
static |
Definition at line 875 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 884 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 links to a directory, it wont be recursed down. Support for this could be added.| 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 1106 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 959 of file fileops_c.cc.
References BLI_assert, dirent::d_name, FILENAME_IS_CURRPAR, free(), 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 1312 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 929 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 921 of file fileops_c.cc.
References free(), and StrBuf::str.
Referenced by recursive_operation().
|
static |
Definition at line 911 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 950 of file fileops_c.cc.
References BLI_assert, len, StrBuf::str, and StrBuf::str_len.
Referenced by recursive_operation_impl().