[vlc-devel] commit: update: allow update_Download to accept: directory, filename, NULL (Derk-Jan Hartman )
git version control
git at videolan.org
Thu Oct 2 21:40:12 CEST 2008
vlc | branch: master | Derk-Jan Hartman <hartman at videolan.org> | Thu Oct 2 16:32:14 2008 +0200| [0f245d7bdd245fb84181d8911d72bbc62f099844] | committer: Derk-Jan Hartman
update: allow update_Download to accept: directory, filename, NULL
directory: accepts any existing directory and will use the filename component of the update URL (old behaviour). This option no longer requires you to provide a string that ends with the pathsep.
filename: write directly to this filename. Existing files will be overwritten.
NULL: will write to filename component of the update URL. likely in the CWD.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0f245d7bdd245fb84181d8911d72bbc62f099844
---
src/misc/update.c | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/misc/update.c b/src/misc/update.c
index c9559ea..2eac20a 100644
--- a/src/misc/update.c
+++ b/src/misc/update.c
@@ -35,6 +35,9 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
#include <vlc_common.h>
#include <vlc_update.h>
@@ -1517,6 +1520,7 @@ static void* update_DownloadReal( vlc_object_t *p_this )
char *psz_tmpdestfile = NULL;
FILE *p_file = NULL;
+ struct stat p_stat;
stream_t *p_stream = NULL;
void* p_buffer = NULL;
int i_read;
@@ -1548,13 +1552,24 @@ static void* update_DownloadReal( vlc_object_t *p_this )
goto end;
}
psz_tmpdestfile++;
- if( asprintf( &psz_destfile, "%s%s", psz_destdir, psz_tmpdestfile ) == -1 )
- goto end;
+
+ if( utf8_stat( psz_destdir, &p_stat) == 0 && (p_stat.st_mode & S_IFDIR) )
+ {
+ if( asprintf( &psz_destfile, "%s%c%s", psz_destdir, DIR_SEP_CHAR, psz_tmpdestfile ) == -1 )
+ goto end;
+ }
+ else if( psz_destdir )
+ psz_destfile = strdup( psz_destdir );
+ else
+ psz_destfile = strdup( psz_tmpdestfile );
p_file = utf8_fopen( psz_destfile, "w" );
if( !p_file )
{
msg_Err( p_udt, "Failed to open %s for writing", psz_destfile );
+ intf_UserFatal( p_udt, true, _("Saving file failed"),
+ _("Failed to open \"%s\" for writing"),
+ psz_destfile );
goto end;
}
More information about the vlc-devel
mailing list