comparison src/org/tmatesoft/hg/util/RegularFileInfo.java @ 619:868b2ffdcd5c

Close FIS, not FileChannel, to clear both references to FileDescriptor right away
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 17 May 2013 22:04:23 +0200
parents c02b5710d9ac
children
comparison
equal deleted inserted replaced
618:7c0d2ce340b8 619:868b2ffdcd5c
64 // since we found this symlink in directory listing, it's safe to say it exists just based on the fact it's link 64 // since we found this symlink in directory listing, it's safe to say it exists just based on the fact it's link
65 return isSymlink() || (file.canRead() && file.isFile()); 65 return isSymlink() || (file.canRead() && file.isFile());
66 } 66 }
67 67
68 public int lastModified() { 68 public int lastModified() {
69 // TODO post-1.0 for symlinks, this returns incorrect mtime of the target file, not that of link itself 69 // TODO [post-1.1] for symlinks, this returns incorrect mtime of the target file, not that of link itself
70 // Besides, timestame if link points to non-existing file is 0. 70 // Besides, timestame if link points to non-existing file is 0.
71 // However, it result only in slowdown in WCStatusCollector, as it need to perform additional content check 71 // However, it result only in slowdown in WCStatusCollector, as it need to perform additional content check
72 return (int) (file.lastModified() / 1000); 72 return (int) (file.lastModified() / 1000);
73 } 73 }
74 74
82 public ReadableByteChannel newInputChannel() { 82 public ReadableByteChannel newInputChannel() {
83 try { 83 try {
84 if (isSymlink()) { 84 if (isSymlink()) {
85 return new ByteArrayReadableChannel(getLinkTargetBytes()); 85 return new ByteArrayReadableChannel(getLinkTargetBytes());
86 } else { 86 } else {
87 // TODO [2.0 API break] might be good idea replace channel with smth
88 // else, to ensure #close() disposes FileDescriptor. Now
89 // FD has usage count of two (new FileInputStream + getChannel),
90 // and FileChannel#close decrements only 1, second has to wait FIS#finalize()
87 return new FileInputStream(file).getChannel(); 91 return new FileInputStream(file).getChannel();
88 } 92 }
89 } catch (FileNotFoundException ex) { 93 } catch (FileNotFoundException ex) {
90 StreamLogFacility.newDefault().dump(getClass(), Info, ex, null); 94 StreamLogFacility.newDefault().dump(getClass(), Info, ex, null);
91 // shall not happen, provided this class is used correctly 95 // shall not happen, provided this class is used correctly