@@ -37,6 +37,10 @@ public class ASAPInternalChunkFS implements ASAPInternalChunk {
3737
3838 @ Override
3939 public void clone (ASAPInternalChunk chunkSource ) throws IOException {
40+ if (metaFile .getAbsolutePath ().contains ("ultihopTests/Alice_42/1/sha" )) {
41+ Log .writeLog (this , this .toString (), "DEBUGGING_Multihop_Bug #2: " + metaFile .exists ());
42+ }
43+
4044 this .uri = chunkSource .getUri ();
4145 this .recipients = chunkSource .getRecipients ();
4246 this .extraData = chunkSource .getExtraData ();
@@ -116,7 +120,7 @@ private void initFiles(String trunkName) throws IOException {
116120 Log .writeLog (this , "meta file does not exist / set up: " + this .metaFile );
117121 if (!this .metaFile .getParentFile ().exists ()) {
118122 this .metaFile .getParentFile ().mkdirs ();
119- Log .writeLog (this , "parent folder created: " + this .messageFile .getParentFile ().exists ());
123+ // Log.writeLog(this, "parent folder created: " + this.messageFile.getParentFile().exists());
120124 }
121125 this .metaFile .createNewFile ();
122126 } else {
@@ -361,22 +365,83 @@ private boolean readMetaData(File metaFile) throws IOException {
361365 return true ;
362366 }
363367
364- private void writeMetaData (File metaFile ) throws IOException {
368+ private void writeMetaData (File file2writeMetaData ) throws IOException {
365369 // write data to metafile
366- DataOutputStream dos = new DataOutputStream (new FileOutputStream (metaFile ));
370+ /*
371+ if(file2writeMetaData.exists()) {
372+ if(file2writeMetaData.getAbsolutePath().contains("ultihopTests/Alice_42/1/sha")) {
373+ Log.writeLog(this, this.toString(), "\nDEBUGGING_Multihop_Bug #1: " +
374+ "\nfile2WriteMetaData:" + file2writeMetaData.getAbsolutePath() +
375+ "\nexists:" + file2writeMetaData.exists() +
376+ "\ncanWrite:" + file2writeMetaData.canWrite()
377+ );
378+ }
379+ this.metaFile.delete();
380+ this.metaFile.createNewFile();
381+ }
382+ */
367383
368- // do it as first element - shure how many bytes we read..
369- ASAPSerialization .writeASAPHopList (this .hopList , dos );
370-
371- dos .writeUTF (this .uri );
372- dos .writeUTF (this .getExtraAsString ());
373- dos .writeUTF (SerializationHelper .collection2String (this .recipients ));
374- dos .writeUTF (SerializationHelper .collection2String (this .deliveredTo ));
384+ try {
385+ /*
386+ if(file2writeMetaData.getAbsolutePath().contains("ultihopTests/Alice_42/1/sha")) {
387+ Log.writeLog(this, this.toString(), "\nDEBUGGING_Multihop_Bug #1: open:" +
388+ "\nfile2WriteMetaData:" + file2writeMetaData.getAbsolutePath() +
389+ "\nexists:" + file2writeMetaData.exists() +
390+ "\ncanWrite:" + file2writeMetaData.canWrite()
391+ );
392+ }
393+ */
394+ FileOutputStream fos = new FileOutputStream (file2writeMetaData );
395+ Log .writeLog (this , this .toString (), "\\ nDEBUGGING_Multihop_Bug: write meta data to:" +
396+ "\n file2WriteMetaData:" + file2writeMetaData .getAbsolutePath () +
397+ "\n exists:" + file2writeMetaData .exists () +
398+ "\n canWrite:" + file2writeMetaData .canWrite ()
399+ );
400+ DataOutputStream dos = new DataOutputStream (fos );
375401
376- // write offsetList
377- dos .writeUTF (this .messageStartOffsetListAsString ());
378-
379- dos .close ();
402+ // do it as first element - shure how many bytes we read..
403+ ASAPSerialization .writeASAPHopList (this .hopList , dos );
404+
405+ dos .writeUTF (this .uri );
406+ dos .writeUTF (this .getExtraAsString ());
407+ dos .writeUTF (SerializationHelper .collection2String (this .recipients ));
408+ dos .writeUTF (SerializationHelper .collection2String (this .deliveredTo ));
409+
410+ // write offsetList
411+ dos .writeUTF (this .messageStartOffsetListAsString ());
412+
413+ fos .close ();
414+ dos .close ();
415+ }
416+ catch (IOException ioe ) {
417+ // TODO: debugging code
418+ Log .writeLog (this , this .toString (), "\n DEBUGGING_Multihop_Bug #3: file2WriteMetaData:" +
419+ "\n file2WriteMetaData:" + file2writeMetaData .getAbsolutePath () +
420+ "\n exists:" + file2writeMetaData .exists () +
421+ "\n canWrite:" + file2writeMetaData .canWrite ());
422+ String fname = new StringTokenizer (ioe .getLocalizedMessage ()).nextToken ();
423+ Log .writeLog (this , this .toString (), "\n DEBUGGING_Multihop_Bug #4: not found" +
424+ "\n file2WriteMetaData:" + file2writeMetaData .getAbsolutePath ());
425+ File fNotFound = new File (fname );
426+ Log .writeLog (this , this .toString (), "\n DEBUGGING_Multihop_Bug #5: file not found" +
427+ "\n file2WriteMetaData:" + fNotFound .getAbsolutePath () +
428+ "\n exists:" + fNotFound .exists () +
429+ "\n canWrite:" + fNotFound .canWrite ());
430+ System .out .flush ();
431+ try {
432+ // debugging output
433+ Thread .sleep (10 );
434+ } catch (InterruptedException e ) {
435+ //throw new RuntimeException(e);
436+ }
437+ Log .writeLog (this , this .toString (), "DEBUGGING_Multihop_Bug - try write again" );
438+ FileOutputStream fos = new FileOutputStream (fNotFound );
439+ fos .write (42 );
440+ // never reaches that point
441+ Log .writeLog (this , this .toString (), "DEBUGGING_Multihop_Bug - wrote" );
442+
443+ throw ioe ;
444+ }
380445 }
381446
382447 private String messageStartOffsetListAsString () {
0 commit comments