View Issue Details

IDProjectCategoryView StatusLast Update
0013415mantisbtattachmentspublic2014-09-23 18:05
Reporteradminactoll Assigned Torombert  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version1.2.8 
Target Version1.2.12Fixed in Version1.2.12 
Summary0013415: cloning issue with attachments doesn't work
Description

(Sorry for my bad english)
When I try to clone a bug with attached file, it doesn't work. The error message is :
SYSTEM WARNING : copy(...) [function.copy]: failed to open stream: No such file or directory
SYSTEM WARNING: chmod() [function.chmod]: No such file or directory

The attached file is correctly uploaded in the original bug report and I'm able to open attached file (in original bug report) correctly.

I spent time to debug this problem andI think the error is in file core/file_api.php between line 873 and 883.

Steps To Reproduce

Clone a bug report with attached file (with the box "clone attachments" selected).

Additional Information

...
$t_file_path = dirname( $t_bug_file['folder'] );
$t_new_diskfile_name = $t_file_path . file_generate_unique_name( 'bug-' . $t_bug_file['filename'], $t_file_path );
...
copy( $t_bug_file['diskfile'], $t_new_diskfile_name );
...

#Error 1: function dirname returns parent directory of the parameter. When the variable $t_new_diskfile_name is created, projet folder of bug report is missing : so, new destintation file is invalid.

#Error 2: About the first parameter of copy function, path of original attached file is missing.

I resolve the problem with :

$t_file_path = $t_bug_file['folder'];
instead of
$t_file_path = dirname( $t_bug_file['folder'] );

AND

copy( $t_file_path.$t_bug_file['diskfile'], $t_new_diskfile_name );
instead of
copy( $t_bug_file['diskfile'], $t_new_diskfile_name );

TagsNo tags attached.
Attached Files
13415-v1.patch (1,131 bytes)   
diff --git a/core/file_api.php b/core/file_api.php
index 0073185..8938886 100644
--- a/core/file_api.php
+++ b/core/file_api.php
@@ -1041,11 +1041,12 @@
 
         # prepare the new diskfile name and then copy the file
         $t_file_path = $t_bug_file['folder'];
-        $t_new_diskfile_name = $t_file_path . file_generate_unique_name( 'bug-' . $t_bug_file['filename'], $t_file_path );
+        $t_new_diskfile_name = file_generate_unique_name( 'bug-' . $t_bug_file['filename'], $t_file_path );
+        $t_new_diskfile_location = $t_file_path . $t_new_diskfile_name;
         $t_new_file_name = file_get_display_name( $t_bug_file['filename'] );
         if(( config_get( 'file_upload_method' ) == DISK ) ) {
-            copy( $t_file_path.$t_bug_file['diskfile'], $t_new_diskfile_name );
-            chmod( $t_new_diskfile_name, config_get( 'attachments_file_permissions' ) );
+            copy( $t_file_path.$t_bug_file['diskfile'], $t_new_diskfile_location );
+            chmod( $t_new_diskfile_location, config_get( 'attachments_file_permissions' ) );
         }
 
         $query = "INSERT INTO $t_mantis_bug_file_table
13415-v1.patch (1,131 bytes)   

Relationships

related to 0015721 closedgrangeway Functionality to consider porting to master-2.0.x 

Activities

rombert

rombert

2011-10-17 10:56

reporter   ~0029973

Will look into this, thanks.

rombert

rombert

2011-11-14 17:07

reporter   ~0030236

Thanks for the report and the patch, I've applied the fix for both 1.2 and 1.3 .

For the future, you could submit pull requests using github to get proper attribution in the codebase.

TomR

TomR

2011-12-23 11:25

reporter   ~0030679

Last edited: 2011-12-23 11:26

I think this does not cover all of it.

My understanding is that in mantis_bug_table the field 'diskfile' should only contains the generated filename WITHOUT the path, because the path is stored in field 'folder'.

However in that case the patch is not complete: You should change line 873

from

$t_new_diskfile_name = $t_file_path . file_generate_unique_name( 'bug-' . $t_bug_file['filename'], $t_file_path );

into

$t_new_diskfile_name = file_generate_unique_name( 'bug-' . $t_bug_file['filename'], $t_file_path );

rombert

rombert

2011-12-27 05:41

reporter   ~0030709

@TomR: Can you give me an example configuration and steps to reproduce?

brahms

brahms

2012-02-05 04:35

reporter   ~0031124

v1.1.18, in mantis_bug_table the field 'diskfile' includes the path, but in v2.1.8, in mantis_bug_table the field 'diskfile' does not includes the path.
in 2.1.8, when I change project path, all attachments missing, wow, see attachment.

rombert

rombert

2012-02-08 13:21

reporter   ~0031196

(In reply to comment 0013415:0031124)

v1.1.18, in mantis_bug_table the field 'diskfile' includes the path, but in
v2.1.8, in mantis_bug_table the field 'diskfile' does not includes the path.
in 2.1.8, when I change project path, all attachments missing, wow, see
attachment.

This seems unrelated to the bug report, please use the forums for support or open a new bug.

atrol

atrol

2012-02-16 06:49

developer   ~0031250

Reopened based on TomR's input 0013415:0030679

  1. set $g_file_upload_method = DISK; and adjust "Upload Path" setting of your project
  2. Enter a new issue with attachment
  3. Clone the issue including attachment

Check column diskfile of table manis_bug_file_table
It contains the diskfilename for the original issue but path + diskfilename for the cloned issue

henrywang

henrywang

2012-04-24 03:36

reporter   ~0031707

Also got the same issue when cloning a bug.
And fix the issue with following changes:

$t_file_path = $t_bug_file['folder'];
instead of
$t_file_path = dirname( $t_bug_file['folder'] );

AND

copy( $t_file_path.$t_bug_file['diskfile'], $t_new_diskfile_name );
instead of
copy( $t_file_path.$t_bug_file['diskfile'], $t_file_path.$t_new_diskfile_name );

AND
$t_new_diskfile_name = $t_file_path . file_generate_unique_name( 'bug-' . $t_bug_file['filename'], $t_file_path );
instead of
$t_new_diskfile_name = file_generate_unique_name( 'bug-' . $t_bug_file['filename'], $t_file_path );

Thus a new file will be created in the same folder of the original file and only file name will be saved to the diskfile column of mantis_bug_file_table.

henrywang

henrywang

2012-04-24 03:38

reporter   ~0031708

the last change should be:
$t_new_diskfile_name = file_generate_unique_name( 'bug-' . $t_bug_file['filename'], $t_file_path );
instead of
$t_new_diskfile_name = $t_file_path . file_generate_unique_name( 'bug-' . $t_bug_file['filename'], $t_file_path );

BTW, if the new folder is different from the older one, there should be more change to fix it.

rombert

rombert

2012-06-13 16:59

reporter   ~0032093

I've managed to reproduce the problem and with this fix I've now validated that cloning issues with attachments work as expected - the files are correctly copied and the diskfile entry is correct as well.

Can anyone validate this patch for me before committing?

atrol

atrol

2012-06-15 06:57

developer   ~0032106

Works for me.
diskfile column does not longer contain the path.

rombert

rombert

2012-06-16 07:22

reporter   ~0032111

(In reply to comment 0013415:0032106)

Works for me.
diskfile column does not longer contain the path.

Thanks for confirming. I was not sure my own tests were correct.

grangeway

grangeway

2013-04-05 17:56

reporter   ~0036148

Marking as 'acknowledged' not resolved/closed to track that change gets ported to master-2.0.x branch

Related Changesets

MantisBT: master 46873ebc

2011-11-14 09:05

rombert


Details Diff
Fix 0013415 ( cloning issue with attachments doesn't work )

Thanks to adminactoll for providing the patch.
Affected Issues
0013415
mod - core/file_api.php Diff File

MantisBT: master-1.2.x 0b8298ec

2011-11-14 09:05

rombert


Details Diff
Fix 0013415 ( cloning issue with attachments doesn't work )

Thanks to adminactoll for providing the patch.
Affected Issues
0013415
mod - core/file_api.php Diff File

MantisBT: master-1.2.x 92d2dc3b

2012-06-16 00:19

rombert


Details Diff
Fix 0013415: cloning issue with attachments doesn't work Affected Issues
0013415
mod - core/file_api.php Diff File

MantisBT: master d8b21506

2012-06-16 00:19

rombert


Details Diff
Fix 0013415: cloning issue with attachments doesn't work Affected Issues
0013415
mod - core/file_api.php Diff File