Page MenuHome

fileops_1.patch

fileops_1.patch

commit 33654b4a8f6833cfbd82d7b0266662df02b79363
Author: Lawrence D'Oliveiro <ldo@geek-central.gen.nz>
Date: Mon Feb 18 01:55:52 2013 +0000
Add comments and use of bool type in fileops.c
diff --git a/source/blender/blenkernel/intern/customdata_file.c b/source/blender/blenkernel/intern/customdata_file.c
index dfaa557..c72eea5 100644
--- a/source/blender/blenkernel/intern/customdata_file.c
+++ b/source/blender/blenkernel/intern/customdata_file.c
@@ -404,7 +404,7 @@ void cdf_write_close(CDataFile *cdf)
void cdf_remove(const char *filename)
{
- BLI_delete(filename, 0, 0);
+ BLI_delete(filename, false, false);
}
/********************************** Layers ***********************************/
diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c
index d4d4e07..cd3357a 100644
--- a/source/blender/blenkernel/intern/packedFile.c
+++ b/source/blender/blenkernel/intern/packedFile.c
@@ -348,7 +348,7 @@ int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, i
}
}
else {
- if (BLI_delete(tempname, 0, 0) != 0) {
+ if (BLI_delete(tempname, false, false) != 0) {
BKE_reportf(reports, RPT_ERROR, "Error deleting '%s' (ignored)", tempname);
}
}
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 27c5e03..6ffb1e2 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -2432,7 +2432,7 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra)
if (mode == PTCACHE_CLEAR_ALL) {
pid->cache->last_exact = MIN2(pid->cache->startframe, 0);
BLI_join_dirfile(path_full, sizeof(path_full), path, de->d_name);
- BLI_delete(path_full, 0, 0);
+ BLI_delete(path_full, false, false);
}
else {
/* read the number of the file */
@@ -2448,7 +2448,7 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra)
{
BLI_join_dirfile(path_full, sizeof(path_full), path, de->d_name);
- BLI_delete(path_full, 0, 0);
+ BLI_delete(path_full, false, false);
if (pid->cache->cached_frames && frame >=sta && frame <= end)
pid->cache->cached_frames[frame-sta] = 0;
}
@@ -2502,7 +2502,7 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra)
if (pid->cache->flag & PTCACHE_DISK_CACHE) {
if (BKE_ptcache_id_exist(pid, cfra)) {
ptcache_filename(pid, filename, cfra, 1, 1); /* no path */
- BLI_delete(filename, 0, 0);
+ BLI_delete(filename, false, false);
}
}
else {
@@ -2820,7 +2820,7 @@ void BKE_ptcache_remove(void)
}
else if (strstr(de->d_name, PTCACHE_EXT)) { /* do we have the right extension?*/
BLI_join_dirfile(path_full, sizeof(path_full), path, de->d_name);
- BLI_delete(path_full, 0, 0);
+ BLI_delete(path_full, false, false);
}
else {
rmdir = 0; /* unknown file, don't remove the dir */
@@ -2834,7 +2834,7 @@ void BKE_ptcache_remove(void)
}
if (rmdir) {
- BLI_delete(path, 1, 0);
+ BLI_delete(path, true, false);
}
}
diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h
index be4dbeb..7c66ec9 100644
--- a/source/blender/blenlib/BLI_fileops.h
+++ b/source/blender/blenlib/BLI_fileops.h
@@ -50,7 +50,7 @@ struct gzFile;
int BLI_exists(const char *path);
int BLI_copy(const char *path, const char *to);
int BLI_rename(const char *from, const char *to);
-int BLI_delete(const char *path, int dir, int recursive);
+int BLI_delete(const char *path, bool dir, bool recursive);
int BLI_move(const char *path, const char *to);
int BLI_create_symlink(const char *path, const char *to);
int BLI_stat(const char *path, struct stat *buffer);
@@ -74,8 +74,8 @@ FILE *BLI_fopen(const char *filename, const char *mode);
void *BLI_gzopen(const char *filename, const char *mode);
int BLI_open(const char *filename, int oflag, int pmode);
-int BLI_file_is_writable(const char *file);
-int BLI_file_touch(const char *file);
+bool BLI_file_is_writable(const char *file);
+bool BLI_file_touch(const char *file);
int BLI_file_gzip(const char *from, const char *to);
char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r);
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index 1cb4d91..1111d0d 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -157,7 +157,7 @@ char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r)
/* return 1 when file can be written */
-int BLI_file_is_writable(const char *filename)
+bool BLI_file_is_writable(const char *filename)
{
int file;
@@ -170,22 +170,24 @@ int BLI_file_is_writable(const char *filename)
file = BLI_open(filename, O_BINARY | O_RDWR | O_CREAT, 0666);
if (file < 0) {
- return 0;
+ return false;
}
else {
/* success, delete the file we create */
close(file);
- BLI_delete(filename, 0, 0);
- return 1;
+ BLI_delete(filename, false, false);
+ return true;
}
}
else {
close(file);
- return 1;
+ return true;
}
}
-int BLI_file_touch(const char *file)
+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 iff successful. */
{
FILE *f = BLI_fopen(file, "r+b");
if (f != NULL) {
@@ -198,9 +200,9 @@ int BLI_file_touch(const char *file)
}
if (f) {
fclose(f);
- return 1;
+ return true;
}
- return 0;
+ return false;
}
#ifdef WIN32
@@ -255,7 +257,7 @@ int BLI_open(const char *filename, int oflag, int pmode)
return uopen(filename, oflag, pmode);
}
-int BLI_delete(const char *file, int dir, int recursive)
+int BLI_delete(const char *file, bol dir, bool recursive)
{
int err;
@@ -391,7 +393,7 @@ int BLI_rename(const char *from, const char *to)
/* make sure the filenames are different (case insensitive) before removing */
if (BLI_exists(to) && BLI_strcasecmp(from, to))
- if (BLI_delete(to, 0, 0)) return 1;
+ if (BLI_delete(to, false, false)) return 1;
return urename(from, to);
}
@@ -589,7 +591,9 @@ int BLI_open(const char *filename, int oflag, int pmode)
return open(filename, oflag, pmode);
}
-int BLI_delete(const char *file, int dir, int recursive)
+int BLI_delete(const char *file, bool dir, bool recursive)
+/* deletes the specified file or directory (depending on dir), optionally
+doing recursive delete of directory contents. */
{
if (strchr(file, '"')) {
printf("Error: not deleted file %s because of quote!\n", file);
@@ -608,20 +612,22 @@ int BLI_delete(const char *file, int dir, int recursive)
return -1;
}
-static int check_the_same(const char *path_a, const char *path_b)
+static bool check_the_same(const char *path_a, const char *path_b)
+/* do the two paths denote the same filesystem object. */
{
struct stat st_a, st_b;
if (lstat(path_a, &st_a))
- return 0;
+ return false;
if (lstat(path_b, &st_b))
- return 0;
+ return false;
return st_a.st_dev == st_b.st_dev && st_a.st_ino == st_b.st_ino;
}
-static int set_permissions(const char *file, struct stat *st)
+static int set_permissions(const char *file, const struct stat *st)
+/* sets the mode and ownership of file to the values from st. */
{
if (chown(file, st->st_uid, st->st_gid)) {
perror("chown");
@@ -894,10 +900,9 @@ int BLI_rename(const char *from, const char *to)
if (!BLI_exists(from)) return 0;
if (BLI_exists(to))
- if (BLI_delete(to, 0, 0)) return 1;
+ if (BLI_delete(to, false, false)) return 1;
return rename(from, to);
}
#endif
-
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index ca18645..d222691 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3160,7 +3160,7 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
return 0;
}
- BLI_delete(tempname, 0, 0);
+ BLI_delete(tempname, false, false);
}
else if (-1==ret) {
BKE_report(reports, RPT_ERROR, "Failed opening .gz file");
diff --git a/source/blender/collada/collada.cpp b/source/blender/collada/collada.cpp
index b3c288c..8f6f949 100644
--- a/source/blender/collada/collada.cpp
+++ b/source/blender/collada/collada.cpp
@@ -84,7 +84,7 @@ int collada_export(Scene *sce,
/* annoying, collada crashes if file cant be created! [#27162] */
if (!BLI_exists(filepath)) {
BLI_make_existing_file(filepath); /* makes the dir if its not there */
- if (BLI_file_touch(filepath) == 0) {
+ if (!BLI_file_touch(filepath)) {
fprintf(stdout, "Collada export: Can not create: %s\n", filepath);
return 0;
}
diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c
index fc55b2b..714b1be 100644
--- a/source/blender/editors/physics/physics_fluid.c
+++ b/source/blender/editors/physics/physics_fluid.c
@@ -679,7 +679,7 @@ static int fluid_init_filepaths(Object *fsDomain, char *targetDir, char *targetF
if (fileCfg) {
dirExist = 1; fclose(fileCfg);
// remove cfg dummy from directory test
- BLI_delete(targetFile, 0, 0);
+ BLI_delete(targetFile, false, false);
}
if (targetDir[0] == '\0' || (!dirExist)) {
@@ -852,9 +852,9 @@ static void fluidsim_delete_until_lastframe(FluidsimSettings *fss, const char *r
curFrame++;
if ((exists = BLI_exists(targetFile))) {
- BLI_delete(targetFile, 0, 0);
- BLI_delete(targetFileVel, 0, 0);
- BLI_delete(previewFile, 0, 0);
+ BLI_delete(targetFile, false, false);
+ BLI_delete(targetFileVel, false, false);
+ BLI_delete(previewFile, false, false);
}
} while (exists);
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 4a70d40..3ffd245 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -1485,7 +1485,7 @@ int file_delete_exec(bContext *C, wmOperator *UNUSED(op))
file = filelist_file(sfile->files, sfile->params->active_file);
BLI_make_file_string(G.main->name, str, sfile->params->dir, file->relname);
- BLI_delete(str, 0, 0);
+ BLI_delete(str, false, false);
ED_fileselect_clear(C, sfile);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 0d1156a..de61981 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -162,7 +162,7 @@ static int space_image_file_exists_poll(bContext *C)
if (BLI_exists(name) == FALSE) {
CTX_wm_operator_poll_msg_set(C, "image file not found");
}
- else if (BLI_file_is_writable(name) == FALSE) {
+ else if (!BLI_file_is_writable(name)) {
CTX_wm_operator_poll_msg_set(C, "image path can't be written to");
}
else {
diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c
index bdf2476..51c6c2f 100644
--- a/source/blender/imbuf/intern/thumbs.c
+++ b/source/blender/imbuf/intern/thumbs.c
@@ -423,7 +423,7 @@ void IMB_thumb_delete(const char *path, ThumbSize size)
return;
}
if (BLI_exists(thumb)) {
- BLI_delete(thumb, 0, 0);
+ BLI_delete(thumb, false, false);
}
}
}
@@ -448,7 +448,7 @@ ImBuf *IMB_thumb_manage(const char *path, ThumbSize size, ThumbSource source)
if (BLI_exists(thumb)) {
/* clear out of date fail case */
if (BLI_file_older(thumb, path)) {
- BLI_delete(thumb, 0, 0);
+ BLI_delete(thumb, false, false);
}
else {
return NULL;
diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c
index e102416..397c38a 100644
--- a/source/blender/render/intern/source/pipeline.c
+++ b/source/blender/render/intern/source/pipeline.c
@@ -1949,7 +1949,7 @@ int RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *r
render_result_exr_file_path(scene, "", 0, str);
- if (BLI_file_is_writable(str) == 0) {
+ if (!BLI_file_is_writable(str)) {
BKE_report(reports, RPT_ERROR, "Cannot save render buffers, check the temp default path");
return 0;
}
@@ -2379,7 +2379,7 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
/* remove touched file */
if (BKE_imtype_is_movie(scene->r.im_format.imtype) == 0) {
if (scene->r.mode & R_TOUCH && BLI_exists(name) && BLI_file_size(name) == 0) {
- BLI_delete(name, 0, 0);
+ BLI_delete(name, false, false);
}
}
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 699bbf5..67422c8 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -1044,7 +1044,7 @@ void wm_autosave_delete(void)
BLI_make_file_string("/", str, BLI_temporary_dir(), BLENDER_QUIT_FILE);
/* if global undo; remove tempsave, otherwise rename */
- if (U.uiflag & USER_GLOBALUNDO) BLI_delete(filename, 0, 0);
+ if (U.uiflag & USER_GLOBALUNDO) BLI_delete(filename, false, false);
else BLI_rename(filename, str);
}
}

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
79/93/6ab03d926ce718ed988e34eae272

Event Timeline