mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-24 21:35:47 +03:00
ownCloud: more memory cleanups, use widechar unlink for tmp files,
adjust the modtime by the time difference between client adn server.
This commit is contained in:
parent
99691059bf
commit
9f4f0e8106
1 changed files with 19 additions and 22 deletions
|
@ -1075,6 +1075,7 @@ static const char* owncloud_file_id( const char *path )
|
||||||
char *uri = _cleanPath(path);
|
char *uri = _cleanPath(path);
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
const char *cbuf = NULL;
|
const char *cbuf = NULL;
|
||||||
|
csync_vio_file_stat_t *fs = NULL;
|
||||||
|
|
||||||
/* Perform an HEAD request to the resource. HEAD delivers the
|
/* Perform an HEAD request to the resource. HEAD delivers the
|
||||||
* ETag header back. */
|
* ETag header back. */
|
||||||
|
@ -1088,32 +1089,32 @@ static const char* owncloud_file_id( const char *path )
|
||||||
* into a PROPFIND request.
|
* into a PROPFIND request.
|
||||||
*/
|
*/
|
||||||
if( ! header ) {
|
if( ! header ) {
|
||||||
csync_vio_file_stat_t *fs = csync_vio_file_stat_new();
|
fs = csync_vio_file_stat_new();
|
||||||
if(fs == NULL) {
|
if(fs == NULL) {
|
||||||
DEBUG_WEBDAV( "owncloud_file_id: memory fault.");
|
DEBUG_WEBDAV( "owncloud_file_id: memory fault.");
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return NULL;
|
return NULL;
|
||||||
};
|
|
||||||
if( owncloud_stat( path, fs ) == 0 ) {
|
|
||||||
header = c_strdup(fs->md5);
|
|
||||||
}
|
}
|
||||||
csync_vio_file_stat_destroy(fs);
|
if( owncloud_stat( path, fs ) == 0 ) {
|
||||||
|
header = fs->md5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In case the result is surrounded by "" cut them away. */
|
/* In case the result is surrounded by "" cut them away. */
|
||||||
if( header ) {
|
if( header ) {
|
||||||
if( header [0] == '"' && header[ strlen(header)-1] == '"') {
|
if( header [0] == '"' && header[ strlen(header)-1] == '"') {
|
||||||
int len = strlen( header )-2;
|
int len = strlen( header )-2;
|
||||||
buf = c_malloc( len );
|
buf = c_malloc( len+1 );
|
||||||
strncpy( buf, header+1, len );
|
strncpy( buf, header+1, len );
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
cbuf = buf;
|
cbuf = buf;
|
||||||
SAFE_FREE(header);
|
/* do not free header here, as it belongs to the request */
|
||||||
} else {
|
} else {
|
||||||
cbuf = header;
|
cbuf = c_strdup(header);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DEBUG_WEBDAV("Get file ID for %s: %s", path, buf);
|
DEBUG_WEBDAV("Get file ID for %s: %s", path, buf ? buf:"<null>");
|
||||||
|
if( fs ) csync_vio_file_stat_destroy(fs);
|
||||||
ne_request_destroy(req);
|
ne_request_destroy(req);
|
||||||
SAFE_FREE(uri);
|
SAFE_FREE(uri);
|
||||||
|
|
||||||
|
@ -1181,6 +1182,7 @@ static csync_vio_method_handle_t *owncloud_open(const char *durl,
|
||||||
} else {
|
} else {
|
||||||
if( owncloud_stat( dir, &statBuf ) == 0 ) {
|
if( owncloud_stat( dir, &statBuf ) == 0 ) {
|
||||||
SAFE_FREE(statBuf.name);
|
SAFE_FREE(statBuf.name);
|
||||||
|
SAFE_FREE(statBuf.md5);
|
||||||
DEBUG_WEBDAV("Directory of file to open exists.");
|
DEBUG_WEBDAV("Directory of file to open exists.");
|
||||||
SAFE_FREE( _lastDir );
|
SAFE_FREE( _lastDir );
|
||||||
_lastDir = c_strdup(dir);
|
_lastDir = c_strdup(dir);
|
||||||
|
@ -1192,6 +1194,7 @@ static csync_vio_method_handle_t *owncloud_open(const char *durl,
|
||||||
SAFE_FREE(dir);
|
SAFE_FREE(dir);
|
||||||
SAFE_FREE(uri);
|
SAFE_FREE(uri);
|
||||||
SAFE_FREE(statBuf.name);
|
SAFE_FREE(statBuf.name);
|
||||||
|
SAFE_FREE(statBuf.md5);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1359,8 +1362,7 @@ static int owncloud_close(csync_vio_method_handle_t *fhandle) {
|
||||||
int rc;
|
int rc;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
const _TCHAR *tmpFileName = 0;
|
const _TCHAR *tmpFileName = NULL;
|
||||||
const char *etag_header = 0;
|
|
||||||
|
|
||||||
writeCtx = (struct transfer_context*) fhandle;
|
writeCtx = (struct transfer_context*) fhandle;
|
||||||
|
|
||||||
|
@ -1428,6 +1430,8 @@ static int owncloud_close(csync_vio_method_handle_t *fhandle) {
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
/* Remove the local file. */
|
||||||
|
_tunlink(tmpFileName);
|
||||||
}
|
}
|
||||||
c_free_multibyte(tmpFileName);
|
c_free_multibyte(tmpFileName);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1447,14 +1451,8 @@ static int owncloud_close(csync_vio_method_handle_t *fhandle) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* get the uniq id request header */
|
|
||||||
etag_header = ne_get_response_header( writeCtx->req, "ETag" );
|
|
||||||
if( etag_header ) {
|
|
||||||
DEBUG_WEBDAV("ETag for file : %s", etag_header);
|
|
||||||
writeCtx->md5 = c_strdup( etag_header );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ne_request_destroy( writeCtx->req );
|
ne_request_destroy( writeCtx->req );
|
||||||
} else {
|
} else {
|
||||||
/* Its a GET request, not much to do in close. */
|
/* Its a GET request, not much to do in close. */
|
||||||
|
@ -1465,11 +1463,10 @@ static int owncloud_close(csync_vio_method_handle_t *fhandle) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Remove the local file. */
|
|
||||||
unlink( writeCtx->tmpFileName );
|
|
||||||
|
|
||||||
/* free mem. Note that the request mem is freed by the ne_request_destroy call */
|
/* free mem. Note that the request mem is freed by the ne_request_destroy call */
|
||||||
SAFE_FREE( writeCtx->tmpFileName );
|
SAFE_FREE( writeCtx->tmpFileName );
|
||||||
|
SAFE_FREE( writeCtx->clean_uri );
|
||||||
SAFE_FREE( writeCtx );
|
SAFE_FREE( writeCtx );
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1771,11 +1768,11 @@ static int owncloud_utimes(const char *uri, const struct timeval *times) {
|
||||||
pname.name = "lastmodified";
|
pname.name = "lastmodified";
|
||||||
|
|
||||||
newmodtime = modtime->tv_sec;
|
newmodtime = modtime->tv_sec;
|
||||||
#if TIMEDELTA
|
|
||||||
DEBUG_WEBDAV("Add a time delta to modtime %lu: %ld",
|
DEBUG_WEBDAV("Add a time delta to modtime %lu: %ld",
|
||||||
modtime->tv_sec, dav_session.time_delta);
|
modtime->tv_sec, dav_session.time_delta);
|
||||||
newmodtime += dav_session.time_delta;
|
newmodtime += dav_session.time_delta;
|
||||||
#endif
|
|
||||||
snprintf( val, sizeof(val), "%ld", newmodtime );
|
snprintf( val, sizeof(val), "%ld", newmodtime );
|
||||||
DEBUG_WEBDAV("Setting LastModified of %s to %s", curi, val );
|
DEBUG_WEBDAV("Setting LastModified of %s to %s", curi, val );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue