[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55037] trunk/blender/source/blender: patch [#34103] fileops_1.patch
Campbell Barton
ideasman42 at gmail.com
Tue Mar 5 04:53:23 CET 2013
Revision: 55037
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55037
Author: campbellbarton
Date: 2013-03-05 03:53:22 +0000 (Tue, 05 Mar 2013)
Log Message:
-----------
patch [#34103] fileops_1.patch
from Lawrence D'Oliveiro (ldo)
Add comments and use of bool type in fileops.c
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/customdata_file.c
trunk/blender/source/blender/blenkernel/intern/packedFile.c
trunk/blender/source/blender/blenkernel/intern/pointcache.c
trunk/blender/source/blender/blenlib/BLI_fileops.h
trunk/blender/source/blender/blenlib/intern/fileops.c
trunk/blender/source/blender/blenloader/intern/writefile.c
trunk/blender/source/blender/collada/collada.cpp
trunk/blender/source/blender/editors/physics/physics_fluid.c
trunk/blender/source/blender/editors/space_file/file_ops.c
trunk/blender/source/blender/editors/space_image/image_ops.c
trunk/blender/source/blender/imbuf/intern/thumbs.c
trunk/blender/source/blender/render/intern/source/pipeline.c
trunk/blender/source/blender/windowmanager/intern/wm_files.c
Modified: trunk/blender/source/blender/blenkernel/intern/customdata_file.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/customdata_file.c 2013-03-05 03:44:47 UTC (rev 55036)
+++ trunk/blender/source/blender/blenkernel/intern/customdata_file.c 2013-03-05 03:53:22 UTC (rev 55037)
@@ -404,7 +404,7 @@
void cdf_remove(const char *filename)
{
- BLI_delete(filename, 0, 0);
+ BLI_delete(filename, false, false);
}
/********************************** Layers ***********************************/
Modified: trunk/blender/source/blender/blenkernel/intern/packedFile.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/packedFile.c 2013-03-05 03:44:47 UTC (rev 55036)
+++ trunk/blender/source/blender/blenkernel/intern/packedFile.c 2013-03-05 03:53:22 UTC (rev 55037)
@@ -348,7 +348,7 @@
}
}
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);
}
}
Modified: trunk/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/pointcache.c 2013-03-05 03:44:47 UTC (rev 55036)
+++ trunk/blender/source/blender/blenkernel/intern/pointcache.c 2013-03-05 03:53:22 UTC (rev 55037)
@@ -2432,7 +2432,7 @@
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 @@
{
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 @@
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 @@
}
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 @@
}
if (rmdir) {
- BLI_delete(path, 1, 0);
+ BLI_delete(path, true, false);
}
}
Modified: trunk/blender/source/blender/blenlib/BLI_fileops.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_fileops.h 2013-03-05 03:44:47 UTC (rev 55036)
+++ trunk/blender/source/blender/blenlib/BLI_fileops.h 2013-03-05 03:53:22 UTC (rev 55037)
@@ -50,7 +50,7 @@
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 @@
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);
@@ -103,5 +103,4 @@
}
#endif
-#endif
-
+#endif /* __BLI_FILEOPS_H__ */
Modified: trunk/blender/source/blender/blenlib/intern/fileops.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/fileops.c 2013-03-05 03:44:47 UTC (rev 55036)
+++ trunk/blender/source/blender/blenlib/intern/fileops.c 2013-03-05 03:53:22 UTC (rev 55037)
@@ -157,7 +157,7 @@
/* 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,26 @@
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)
+/**
+ * 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)
+ */
+bool BLI_file_touch(const char *file)
{
FILE *f = BLI_fopen(file, "r+b");
if (f != NULL) {
@@ -198,9 +202,9 @@
}
if (f) {
fclose(f);
- return 1;
+ return true;
}
- return 0;
+ return false;
}
#ifdef WIN32
@@ -255,7 +259,7 @@
return uopen(filename, oflag, pmode);
}
-int BLI_delete(const char *file, int dir, int recursive)
+int BLI_delete(const char *file, bool dir, bool recursive)
{
int err;
@@ -391,7 +395,7 @@
/* 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 +593,11 @@
return open(filename, oflag, pmode);
}
-int BLI_delete(const char *file, int dir, int recursive)
+/**
+ * Deletes the specified file or directory (depending on dir), optionally
+ * doing recursive delete of directory contents.
+ */
+int BLI_delete(const char *file, bool dir, bool recursive)
{
if (strchr(file, '"')) {
printf("Error: not deleted file %s because of quote!\n", file);
@@ -608,20 +616,26 @@
return -1;
}
-static int check_the_same(const char *path_a, const char *path_b)
+/**
+ * Do the two paths denote the same filesystem object?
+ */
+static bool check_the_same(const char *path_a, const char *path_b)
{
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)
+/**
+ * Sets the mode and ownership of file to the values from st.
+ */
+static int set_permissions(const char *file, const struct stat *st)
{
if (chown(file, st->st_uid, st->st_gid)) {
perror("chown");
@@ -894,10 +908,9 @@
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
-
Modified: trunk/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/writefile.c 2013-03-05 03:44:47 UTC (rev 55036)
+++ trunk/blender/source/blender/blenloader/intern/writefile.c 2013-03-05 03:53:22 UTC (rev 55037)
@@ -3160,7 +3160,7 @@
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");
Modified: trunk/blender/source/blender/collada/collada.cpp
===================================================================
--- trunk/blender/source/blender/collada/collada.cpp 2013-03-05 03:44:47 UTC (rev 55036)
+++ trunk/blender/source/blender/collada/collada.cpp 2013-03-05 03:53:22 UTC (rev 55037)
@@ -85,7 +85,7 @@
/* 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;
}
Modified: trunk/blender/source/blender/editors/physics/physics_fluid.c
===================================================================
--- trunk/blender/source/blender/editors/physics/physics_fluid.c 2013-03-05 03:44:47 UTC (rev 55036)
+++ trunk/blender/source/blender/editors/physics/physics_fluid.c 2013-03-05 03:53:22 UTC (rev 55037)
@@ -679,7 +679,7 @@
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 @@
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);
Modified: trunk/blender/source/blender/editors/space_file/file_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/file_ops.c 2013-03-05 03:44:47 UTC (rev 55036)
+++ trunk/blender/source/blender/editors/space_file/file_ops.c 2013-03-05 03:53:22 UTC (rev 55037)
@@ -1484,7 +1484,7 @@
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);
Modified: trunk/blender/source/blender/editors/space_image/image_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_ops.c 2013-03-05 03:44:47 UTC (rev 55036)
+++ trunk/blender/source/blender/editors/space_image/image_ops.c 2013-03-05 03:53:22 UTC (rev 55037)
@@ -162,7 +162,7 @@
if (BLI_exists(name) == FALSE) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list