diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-13 00:16:53 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-13 00:16:53 +0300 |
commit | bdfe7d89e2f1292644577972c716931b4ce3c6c3 (patch) | |
tree | d00eb50b749cb001e2b08272c91791e66740b05d /source/blender/blenlib/intern/fileops.c | |
parent | 78a1c27c4a6abe0ed31ca93ad21910f3df04da56 (diff) | |
parent | 7e4db234cee71ead34ee81a12e27da4bd548eb4b (diff) |
Merge of trunk into blender 2.5:
svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r12987:17416
Issues:
* GHOST/X11 had conflicting changes. Some code was added in 2.5, which was
later added in trunk also, but reverted partially, specifically revision
16683. I have left out this reversion in the 2.5 branch since I think it is
needed there.
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16683
* Scons had various conflicting changes, I decided to go with trunk version
for everything except priorities and some library renaming.
* In creator.c, there were various fixes and fixes for fixes related to the -w
-W and -p options. In 2.5 -w and -W is not coded yet, and -p is done
differently. Since this is changed so much, and I don't think those fixes
would be needed in 2.5, I've left them out.
* Also in creator.c: there was code for a python bugfix where the screen was not
initialized when running with -P. The code that initializes the screen there
I had to disable, that can't work in 2.5 anymore but left it commented as a
reminder.
Further I had to disable some new function calls. using src/ and python/, as
was done already in this branch, disabled function calls:
* bpath.c: error reporting
* BME_conversions.c: editmesh conversion functions.
* SHD_dynamic: disabled almost completely, there is no python/.
* KX_PythonInit.cpp and Ketsji/ build files: Mathutils is not there, disabled.
* text.c: clipboard copy call.
* object.c: OB_SUPPORT_MATERIAL.
* DerivedMesh.c and subsurf_ccg, stipple_quarttone.
Still to be done:
* Go over files and functions that were moved to a different location but could
still use changes that were done in trunk.
Diffstat (limited to 'source/blender/blenlib/intern/fileops.c')
-rw-r--r-- | source/blender/blenlib/intern/fileops.c | 108 |
1 files changed, 69 insertions, 39 deletions
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index f55cd05e53e..a64185a896a 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -6,7 +6,7 @@ * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -56,6 +56,8 @@ #include "BKE_utildefines.h" #include <errno.h> +#include "BLO_sys_types.h" // for intptr_t support + /* implementations: */ char *first_slash(char *string) { char *ffslash, *fbslash; @@ -66,11 +68,11 @@ char *first_slash(char *string) { if (!ffslash) return fbslash; else if (!fbslash) return ffslash; - if ((long)ffslash < (long)fbslash) return ffslash; + if ((intptr_t)ffslash < (intptr_t)fbslash) return ffslash; else return fbslash; } -char *BLI_last_slash(char *string) { +char *BLI_last_slash(const char *string) { char *lfslash, *lbslash; lfslash= strrchr(string, '/'); @@ -79,10 +81,43 @@ char *BLI_last_slash(char *string) { if (!lfslash) return lbslash; else if (!lbslash) return lfslash; - if ((long)lfslash < (long)lbslash) return lbslash; + if ((intptr_t)lfslash < (intptr_t)lbslash) return lbslash; else return lfslash; } +/* adds a slash if there isnt one there alredy */ +void BLI_add_slash(char *string) { + int len = strlen(string); +#ifdef WIN32 + if (len==0 || string[len-1]!='\\') { + string[len] = '\\'; + string[len+1] = '\0'; + } +#else + if (len==0 || string[len-1]!='/') { + string[len] = '/'; + string[len+1] = '\0'; + } +#endif +} + +/* removes a slash if there is one */ +void BLI_del_slash(char *string) { + int len = strlen(string); + while (len) { +#ifdef WIN32 + if (string[len-1]=='\\') { +#else + if (string[len-1]=='/') { +#endif + string[len-1] = '\0'; + len--; + } else { + break; + } + } +} + /* gzip the file in from and write it to "to". return -1 if zlib fails, -2 if the originating file does not exist note: will remove the "from" file @@ -131,6 +166,23 @@ int BLI_is_writable(char *filename) } } +int BLI_touch(const char *file) +{ + FILE *f = fopen(file,"r+b"); + if (f != NULL) { + char c = getc(f); + rewind(f); + putc(c,f); + } else { + f = fopen(file,"wb"); + } + if (f) { + fclose(f); + return 1; + } + return 0; +} + #ifdef WIN32 static char str[MAXPATHLEN+12]; @@ -152,12 +204,6 @@ int BLI_delete(char *file, int dir, int recursive) { return err; } -int BLI_touch(char *file) { - callLocalErrorCallBack("Touching files is unsupported on Windows"); - - return 1; -} - int BLI_move(char *file, char *to) { int err; @@ -214,12 +260,6 @@ int BLI_link(char *file, char *to) { return 1; } -int BLI_backup(char *file, char *from, char *to) { - callLocalErrorCallBack("Backing up files is unsupported on Windows"); - - return 1; -} - int BLI_exists(char *file) { return (GetFileAttributes(file) != 0xFFFFFFFF); } @@ -257,7 +297,8 @@ void BLI_recurdir_fileops(char *dirname) { int BLI_rename(char *from, char *to) { if (!BLI_exists(from)) return 0; - if (BLI_exists(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; return rename(from, to); @@ -278,26 +319,21 @@ int BLI_delete(char *file, int dir, int recursive) printf("Error: not deleted file %s because of quote!\n", file); } else { - if (recursive) sprintf(str, "/bin/rm -rf \"%s\"", file); - else if (dir) sprintf(str, "/bin/rmdir \"%s\"", file); - else sprintf(str, "/bin/rm -f \"%s\"", file); - - return system(str); + if (recursive) { + sprintf(str, "/bin/rm -rf \"%s\"", file); + return system(str); + } + else if (dir) { + sprintf(str, "/bin/rmdir \"%s\"", file); + return system(str); + } + else { + return remove(file); //sprintf(str, "/bin/rm -f \"%s\"", file); + } } return -1; } -int BLI_touch(char *file) -{ - - if( BLI_exists("/bin/touch") ) - sprintf(str, "/bin/touch %s", file); - else - sprintf(str, "/usr/bin/touch %s", file); - - return system(str); -} - int BLI_move(char *file, char *to) { sprintf(str, "/bin/mv -f \"%s\" \"%s\"", file, to); @@ -316,12 +352,6 @@ int BLI_link(char *file, char *to) { return system(str); } -int BLI_backup(char *file, char *from, char *to) { - sprintf(str, "/bin/su root -c 'cd %s; /bin/tar cf - \"%s\" | (/bin/cd %s; /bin/tar xf -)'", from, file, to); - - return system(str); -} - int BLI_exists(char *file) { return BLI_exist(file); } |