[LON-CAPA-cvs] cvs: loncom /homework daxesave.pm

raeburn raeburn at source.lon-capa.org
Wed Aug 23 16:43:34 EDT 2023


raeburn		Wed Aug 23 20:43:34 2023 EDT

  Modified files:              
    /loncom/homework	daxesave.pm 
  Log:
  - Coding style. use strict, check file could be opened for writing.
  
  
Index: loncom/homework/daxesave.pm
diff -u loncom/homework/daxesave.pm:1.5 loncom/homework/daxesave.pm:1.6
--- loncom/homework/daxesave.pm:1.5	Tue Dec 13 21:37:35 2016
+++ loncom/homework/daxesave.pm	Wed Aug 23 20:43:34 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Convert and save a problem from Daxe.
 #
-# $Id: daxesave.pm,v 1.5 2016/12/13 21:37:35 damieng Exp $
+# $Id: daxesave.pm,v 1.6 2023/08/23 20:43:34 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -28,8 +28,9 @@
 ###
 
 package Apache::daxesave;
+use strict;
 
-use Apache::Constants;
+use Apache::Constants qw(:common);
 use Apache::lonnet;
 use Try::Tiny;
 use File::Copy;
@@ -99,11 +100,13 @@
     if (-e $newpath) {
         copy($newpath, $filebak); # errors ignored
     }
-    open my $out, $mode, $newpath;
-    print $out $contents;
-    close $out;
-    
-    $request->print("ok\n");
+    if (open(my $out, $mode, $newpath)) {
+        print $out $contents;
+        close $out;
+        $request->print("ok\n");
+    } else {
+        $request->print("error\nFailed to open file to save $path");
+    }
     return OK;
 }
 




More information about the LON-CAPA-cvs mailing list