@@ -174,7 +174,7 @@ def preprocess_file_and_save_result(
174
174
result = preprocessor (output_directory , filepath , all_files , includes , stats ,
175
175
hip_clang_launch , is_pytorch_extension , clean_ctx , show_progress )
176
176
177
- fin_path = os .path .join (output_directory , filepath )
177
+ fin_path = os .path .abspath ( os . path . join (output_directory , filepath ) )
178
178
# Show what happened
179
179
if show_progress :
180
180
print (
@@ -711,7 +711,7 @@ def preprocessor(
711
711
clean_ctx : GeneratedFileCleaner ,
712
712
show_progress : bool ) -> HipifyResult :
713
713
""" Executes the CUDA -> HIP conversion on the specified file. """
714
- fin_path = os .path .join (output_directory , filepath )
714
+ fin_path = os .path .abspath ( os . path . join (output_directory , filepath ) )
715
715
716
716
with open (fin_path , 'r' , encoding = 'utf-8' ) as fin :
717
717
if fin .readline () == HIPIFY_C_BREADCRUMB :
@@ -721,7 +721,7 @@ def preprocessor(
721
721
722
722
orig_output_source = output_source
723
723
724
- fout_path = os .path .join (output_directory , get_hip_file_path (filepath , is_pytorch_extension ))
724
+ fout_path = os .path .abspath ( os . path . join (output_directory , get_hip_file_path (filepath , is_pytorch_extension ) ))
725
725
if not os .path .exists (os .path .dirname (fout_path )):
726
726
clean_ctx .makedirs (os .path .dirname (fout_path ))
727
727
@@ -829,9 +829,14 @@ def repl(m):
829
829
with open (fout_path , 'r' , encoding = 'utf-8' ) as fout_old :
830
830
do_write = fout_old .read () != output_source
831
831
if do_write :
832
- with clean_ctx .open (fout_path , 'w' , encoding = 'utf-8' ) as fout :
833
- fout .write (output_source )
834
- return {"hipified_path" : fout_path , "status" : "ok" }
832
+ try :
833
+ with clean_ctx .open (fout_path , 'w' , encoding = 'utf-8' ) as fout :
834
+ fout .write (output_source )
835
+ return {"hipified_path" : fout_path , "status" : "ok" }
836
+ except PermissionError as e :
837
+ print (f"{ bcolors .WARNING } Failed to save { fout_path } with \" { e .strerror } \" , leaving { fin_path } unchanged.{ bcolors .ENDC } " ,
838
+ file = sys .stderr )
839
+ return {"hipified_path" : fin_path , "status" : "skipped" }
835
840
else :
836
841
return {"hipified_path" : fout_path , "status" : "skipped" }
837
842
0 commit comments