Skip to content

Commit

Permalink
don't resize file on disk for file transfers
Browse files Browse the repository at this point in the history
as requested; causes some issues with NTFS support on some systems
  • Loading branch information
Gregory Mullen (grayhatter) committed May 18, 2015
1 parent 6a4da3b commit 2d7e38a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 32 deletions.
6 changes: 1 addition & 5 deletions android/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ void flush_file(FILE *file)
fsync(fd);
}

int resize_file(FILE *file, uint64_t size){
// File transfers unsupported on android TODO
}

int ch_mod(uint8_t *file){
/* You're probably looking for ./xlib as android isn't working when this was written. */
return -1;
Expand Down Expand Up @@ -813,6 +809,6 @@ __attribute__ ((externally_visible)) void ANativeActivity_onCreate(ANativeActivi
pthread_create(&thread, &myattr, (void*(*)(void*))android_main, NULL);
}

void launch_at_startup(int is_launch_at_startup)
void launch_at_startup(int is_launch_at_startup)
{
}
15 changes: 4 additions & 11 deletions file_transfers.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,15 @@ static void incoming_file_callback_request(Tox *tox, uint32_t friend_number, uin
if(file){
/* File exist, and is readable, now get current size! */
debug("FileTransfer:\tCool file exists, let try to restart it.\n");
/* Eventually we want to cancel the file if it's larger than the incoming size, but without an error
dialog we'll just wait for now...
fseeko(file, 0, SEEK_END); size = ftello(file); fclose(file);
if(file_size != size){
if(file_size <= size){
debug("FileTransfer:\tIncoming size (%lu), and size on disk (%lu) mismatch, aborting!\n", size, file_size);
file_transfer_local_control(tox, friend_number, file_number, TOX_FILE_CONTROL_CANCEL);
free(file_handle->path);
return;
}
}*/
file = fopen((const char*)file_handle->path, "rb+");
/* We have to open as rb+, so we also need to re-seek to the start! */
fseeko(file, 0, SEEK_SET);
Expand Down Expand Up @@ -942,15 +944,6 @@ int utox_file_start_write(uint32_t friend_number, uint32_t file_number, void *fi
utox_break_file(file_handle);
return -1;
}
if(resize_file(file_handle->file, file_handle->size) != 0){
debug("FileTransfer:\tThe file size was unable to be changed!\n");
fclose(file_handle->file);
file_handle->file = NULL;
utox_break_file(file_handle);
remove(filepath);
free(filepath);
return -1;
}

file_handle->path = (uint8_t*)strdup((const char*)filepath);
file_handle->path_length = strlen(filepath);
Expand Down
4 changes: 0 additions & 4 deletions windows/main.7.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

#include <windows.h>

int resize_file(FILE *file, uint64_t size){
return _chsize_s(fileno(file), size);
}

void launch_at_startup(int is_launch_at_startup){
HKEY hKey;
const wchar_t* run_key_path = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
Expand Down
5 changes: 0 additions & 5 deletions windows/main.XP.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
int resize_file(FILE *file, uint64_t size){
return _chsize_s(fileno(file), size);
}


void launch_at_startup(int is_launch_at_startup){
HKEY hKey;
const wchar_t* run_key_path = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
Expand Down
9 changes: 2 additions & 7 deletions xlib/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void send_message(
long data3 /* message data 3 */
){
XEvent ev;

memset(&ev, 0, sizeof(ev));
ev.xclient.type = ClientMessage;
ev.xclient.window = w;
Expand Down Expand Up @@ -828,11 +828,6 @@ void flush_file(FILE *file)
fsync(fd);
}

int resize_file(FILE *file, uint64_t size){
return posix_fallocate(fileno(file), 0, size);
}


void setscale(void)
{
int i;
Expand Down Expand Up @@ -1571,6 +1566,6 @@ int video_getframe(vpx_image_t *image)
return v4l_getframe(image);
}

void launch_at_startup(int is_launch_at_startup)
void launch_at_startup(int is_launch_at_startup)
{
}

0 comments on commit 2d7e38a

Please sign in to comment.