It's a great module, but the default behavior is a bit strange. It's very slowly when I moving file from the attaching directory to the target directory.

I looked into the source codes and drupal apis, it used file_unmanaged_copy even if I just need to move file. but file_unmanaged_move does not solve this problem because it's use file_unmanaged_copy inside too ( unbelievable but yes ).

So I did some home work like below, use PHP original function rename instead of file_unmanaged_copy to move files.

I changed sources/attach.inc on line 250, sorry I don't know how to make .diff files and I'm not sure will this is going to crash on other's sites.

// Save the file to the new location.
// Delete the original file if "moving" the file instead of copying.
if ($instance['widget']['settings']['filefield_sources']['source_attach']['attach_mode'] !== 'copy') {
	global $user;
	$file = new stdClass();
	$file->uid      = $user->uid;
	$file->status   = 0;
	$file->filename = trim(basename($filepath), '.');
	$file->uri      = $directory.'/'.$file->filename;
	$file->filemime = file_get_mimetype($file->filename);
	$file->filesize = filesize($filepath);
	watchdog('file', 'move file from %source to %destination', array('%source'=>$filepath, '%destination'=>$file->uri));
	if(@rename($filepath, $file->uri)){
		$item = array_merge($item, (array) file_save($file));
		@unlink($filepath);
	}			
}else{
	if ($file = filefield_sources_save_file($filepath, $validators, $directory)) {
		$item = array_merge($item, (array) $file);
	}
}

It boosts your moving file as a rocket! I used to spend tens of minutes to move large video file, now it only spends seconds, That's great.

Hope this will help any others.

If this is not what you want, never mind, it's a small hack.

If it's not a perfect solution, help me out, Thank you.

Comments

im0000’s picture

Issue summary: View changes
im0000’s picture

Issue summary: View changes
im0000’s picture

It's a bit strange that according to my watchdog message:

move file from public://film_attach/blended.2014.bluray.720p.dts_.x264-chd.mkv to public://videos/original/blended.2014.bluray.720p.dts_.x264-chd.mkv

the file path it's using a drupal path prefix, but do not know how would the PHP original rename function works correctly with it, did drupal overridden this rename but not covered in API docs?