[LON-CAPA-cvs] cvs: loncom /interface londocs.pm

raeburn raeburn@source.lon-capa.org
Mon, 15 Dec 2008 06:09:37 -0000


raeburn		Mon Dec 15 06:09:37 2008 EDT

  Modified files:              
    /loncom/interface	londocs.pm 
  Log:
  - Repeated copying/pasting of maps would result in very long filenames.
    - Eventually replication to homeserver would fail becuase the .sequence.in.transit file name is too long. (255 character max)
  - Now when copying previously copied folders, truncate number portion to include only the final 10 digits (timestamp of previous copy).
  - &uniqueness_check() checks if file name of new page/sequence to be added does not already occur in the map to which it is being added.   
  
  
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.321 loncom/interface/londocs.pm:1.322
--- loncom/interface/londocs.pm:1.321	Mon Dec 15 03:02:19 2008
+++ loncom/interface/londocs.pm	Mon Dec 15 06:09:37 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.321 2008/12/15 03:02:19 raeburn Exp $
+# $Id: londocs.pm,v 1.322 2008/12/15 06:09:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1281,8 +1281,32 @@
     if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
 	$title=&mt('Copy of').' '.$title;
 	my $newid=$$.time;
-	$url=~/^(.+)\.(\w+)$/;
-	my $newurl=$1.$newid.'.'.$2;
+	my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
+        if ($oldid =~ m{^(/uploaded/\Q$coursedom\E/\Q$coursenum\E/)(\D+)(\d+)$}) {
+            my $path = $1;
+            my $prefix = $2;
+            my $ancestor = $3;
+            if (length($ancestor) > 10) {
+                $ancestor = substr($ancestor,-10,10);
+            }
+            $oldid = $path.$prefix.$ancestor;
+        }
+        my $counter = 0;
+        my $newurl=$oldid.$newid.'.'.$ext;
+        my $is_unique = &uniqueness_check($newurl);
+        while (!$is_unique && $counter < 100) {
+            $counter ++;
+            $newid ++;
+            $newurl = $oldid.$newid;
+            $is_unique = &uniqueness_check($newurl);
+        }
+        if (!$is_unique) {
+            if ($url=~/\.page$/) {
+                return &mt('Paste failed: an error occurred creating a unique URL for the composite page');
+            } else {
+                return &mt('Paste failed: an error occurred creating a unique URL for the folder');
+            }
+        }
 	my $storefn=$newurl;
 	$storefn=~s{^/\w+/$match_domain/$match_username/}{};
 	my $paste_map_result =
@@ -1340,6 +1364,20 @@
 # Store the result
 }
 
+sub uniqueness_check {
+    my ($newurl) = @_;
+    my $unique = 1;
+    foreach my $res (@LONCAPA::map::order) {
+        my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
+        $url=&LONCAPA::map::qtescape($url);
+        if ($newurl eq $url) {
+            $unique = 0;
+            last;    
+        }
+    }
+    return $unique;
+}
+
 my %parameter_type = ( 'randompick'     => 'int_pos',
 		       'hiddenresource' => 'string_yesno',
 		       'encrypturl'     => 'string_yesno',