Mercurial > jhg
annotate src/org/tmatesoft/hg/util/RegularFileInfo.java @ 629:5f52074707b2
Diff/blame methods as command, their residence in HgDataFile was a mistake
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Wed, 22 May 2013 16:46:15 +0200 | 
| parents | 868b2ffdcd5c | 
| children | 
| rev | line source | 
|---|---|
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
1 /* | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
2 * Copyright (c) 2011-2012 TMate Software Ltd | 
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
3 * | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
4 * This program is free software; you can redistribute it and/or modify | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
5 * it under the terms of the GNU General Public License as published by | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
6 * the Free Software Foundation; version 2 of the License. | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
7 * | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
8 * This program is distributed in the hope that it will be useful, | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
11 * GNU General Public License for more details. | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
12 * | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
13 * For information on how to redistribute this software under | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
14 * the terms of a license other than GNU General Public License | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
15 * contact TMate Software at support@hg4j.com | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
16 */ | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
17 package org.tmatesoft.hg.util; | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
18 | 
| 
456
 
909306e412e2
Refactor LogFacility and SessionContext, better API for both
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
425 
diff
changeset
 | 
19 import static org.tmatesoft.hg.util.LogFacility.Severity.Info; | 
| 
 
909306e412e2
Refactor LogFacility and SessionContext, better API for both
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
425 
diff
changeset
 | 
20 | 
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
21 import java.io.File; | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
22 import java.io.FileInputStream; | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
23 import java.io.FileNotFoundException; | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
24 import java.io.IOException; | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
25 import java.nio.ByteBuffer; | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
26 import java.nio.channels.ClosedChannelException; | 
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
27 import java.nio.channels.ReadableByteChannel; | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
28 | 
| 
425
 
48f993aa2f41
FIXMEs: exceptions, javadoc
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
413 
diff
changeset
 | 
29 import org.tmatesoft.hg.core.SessionContext; | 
| 
295
 
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
287 
diff
changeset
 | 
30 import org.tmatesoft.hg.internal.StreamLogFacility; | 
| 
 
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
287 
diff
changeset
 | 
31 | 
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
32 /** | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
33 * | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
34 * @author Artem Tikhomirov | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
35 * @author TMate Software Ltd. | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
36 */ | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
37 public class RegularFileInfo implements FileInfo { | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
38 private final boolean supportsExec, supportsLink; | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
39 private final RegularFileStats fileFlagsHelper; // null if both supportsLink and supportExec are false | 
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
40 private File file; | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
41 | 
| 
425
 
48f993aa2f41
FIXMEs: exceptions, javadoc
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
413 
diff
changeset
 | 
42 public RegularFileInfo(SessionContext ctx) { | 
| 
 
48f993aa2f41
FIXMEs: exceptions, javadoc
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
413 
diff
changeset
 | 
43 this(ctx, false, false); | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
44 } | 
| 
425
 
48f993aa2f41
FIXMEs: exceptions, javadoc
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
413 
diff
changeset
 | 
45 public RegularFileInfo(SessionContext ctx, boolean supportExecFlag, boolean supportSymlink) { | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
46 supportsLink = supportSymlink; | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
47 supportsExec = supportExecFlag; | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
48 if (supportSymlink || supportExecFlag) { | 
| 
425
 
48f993aa2f41
FIXMEs: exceptions, javadoc
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
413 
diff
changeset
 | 
49 fileFlagsHelper = new RegularFileStats(ctx); | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
50 } else { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
51 fileFlagsHelper = null; | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
52 } | 
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
53 } | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
54 | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
55 public void init(File f) { | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
56 file = f; | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
57 if (fileFlagsHelper != null) { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
58 fileFlagsHelper.init(file); | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
59 } | 
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
60 } | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
61 | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
62 public boolean exists() { | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
63 // java.io.File for symlinks without proper target says it doesn't exist. | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
64 // since we found this symlink in directory listing, it's safe to say it exists just based on the fact it's link | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
65 return isSymlink() || (file.canRead() && file.isFile()); | 
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
66 } | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
67 | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
68 public int lastModified() { | 
| 
619
 
868b2ffdcd5c
Close FIS, not FileChannel, to clear both references to FileDescriptor right away
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
476 
diff
changeset
 | 
69 // TODO [post-1.1] for symlinks, this returns incorrect mtime of the target file, not that of link itself | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
70 // Besides, timestame if link points to non-existing file is 0. | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
71 // However, it result only in slowdown in WCStatusCollector, as it need to perform additional content check | 
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
72 return (int) (file.lastModified() / 1000); | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
73 } | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
74 | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
75 public long length() { | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
76 if (isSymlink()) { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
77 return getLinkTargetBytes().length; | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
78 } | 
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
79 return file.length(); | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
80 } | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
81 | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
82 public ReadableByteChannel newInputChannel() { | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
83 try { | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
84 if (isSymlink()) { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
85 return new ByteArrayReadableChannel(getLinkTargetBytes()); | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
86 } else { | 
| 
619
 
868b2ffdcd5c
Close FIS, not FileChannel, to clear both references to FileDescriptor right away
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
476 
diff
changeset
 | 
87 // TODO [2.0 API break] might be good idea replace channel with smth | 
| 
 
868b2ffdcd5c
Close FIS, not FileChannel, to clear both references to FileDescriptor right away
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
476 
diff
changeset
 | 
88 // else, to ensure #close() disposes FileDescriptor. Now | 
| 
 
868b2ffdcd5c
Close FIS, not FileChannel, to clear both references to FileDescriptor right away
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
476 
diff
changeset
 | 
89 // FD has usage count of two (new FileInputStream + getChannel), | 
| 
 
868b2ffdcd5c
Close FIS, not FileChannel, to clear both references to FileDescriptor right away
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
476 
diff
changeset
 | 
90 // and FileChannel#close decrements only 1, second has to wait FIS#finalize() | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
91 return new FileInputStream(file).getChannel(); | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
92 } | 
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
93 } catch (FileNotFoundException ex) { | 
| 
456
 
909306e412e2
Refactor LogFacility and SessionContext, better API for both
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
425 
diff
changeset
 | 
94 StreamLogFacility.newDefault().dump(getClass(), Info, ex, null); | 
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
95 // shall not happen, provided this class is used correctly | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
96 return new ByteArrayReadableChannel(null); | 
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
97 } | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
98 } | 
| 
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
99 | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
100 public boolean isExecutable() { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
101 return supportsExec && fileFlagsHelper.isExecutable(); | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
102 } | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
103 | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
104 public boolean isSymlink() { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
105 return supportsLink && fileFlagsHelper.isSymlink(); | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
106 } | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
107 | 
| 
476
 
c02b5710d9ac
Defect: only first file in directory got flags initialized
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
456 
diff
changeset
 | 
108 @Override | 
| 
 
c02b5710d9ac
Defect: only first file in directory got flags initialized
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
456 
diff
changeset
 | 
109 public String toString() { | 
| 
 
c02b5710d9ac
Defect: only first file in directory got flags initialized
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
456 
diff
changeset
 | 
110 char t = exists() ? (isExecutable() ? '*' : (isSymlink() ? '@' : '-')) : '!'; | 
| 
 
c02b5710d9ac
Defect: only first file in directory got flags initialized
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
456 
diff
changeset
 | 
111 return String.format("RegularFileInfo[%s %c]", file.getPath(), t); | 
| 
 
c02b5710d9ac
Defect: only first file in directory got flags initialized
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
456 
diff
changeset
 | 
112 } | 
| 
 
c02b5710d9ac
Defect: only first file in directory got flags initialized
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
456 
diff
changeset
 | 
113 | 
| 
413
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
114 private byte[] getLinkTargetBytes() { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
115 assert isSymlink(); | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
116 // no idea what encoding Mercurial uses for link targets, assume platform native is ok | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
117 return fileFlagsHelper.getSymlinkTarget().getBytes(); | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
118 } | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
119 | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
120 | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
121 private static class ByteArrayReadableChannel implements ReadableByteChannel { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
122 private final byte[] data; | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
123 private boolean closed = false; // initially open | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
124 private int firstAvailIndex = 0; | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
125 | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
126 ByteArrayReadableChannel(byte[] dataToStream) { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
127 data = dataToStream; | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
128 } | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
129 | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
130 public boolean isOpen() { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
131 return !closed; | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
132 } | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
133 | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
134 public void close() throws IOException { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
135 closed = true; | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
136 } | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
137 | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
138 public int read(ByteBuffer dst) throws IOException { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
139 if (closed) { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
140 throw new ClosedChannelException(); | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
141 } | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
142 int remainingBytes = data.length - firstAvailIndex; | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
143 if (data == null || remainingBytes == 0) { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
144 // EOF right away | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
145 return -1; | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
146 } | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
147 int x = Math.min(dst.remaining(), remainingBytes); | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
148 for (int i = firstAvailIndex, lim = firstAvailIndex + x; i < lim; i++) { | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
149 dst.put(data[i]); | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
150 } | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
151 firstAvailIndex += x; | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
152 return x; | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
153 } | 
| 
 
7f27122011c3
Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents: 
295 
diff
changeset
 | 
154 } | 
| 
287
 
ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
 
Artem Tikhomirov <tikhomirov.artem@gmail.com> 
parents:  
diff
changeset
 | 
155 } | 
