|
21 | 21 | import com.google.devtools.build.lib.util.Blocker; |
22 | 22 | import com.google.devtools.build.lib.util.OS; |
23 | 23 | import com.google.devtools.build.lib.util.StringEncoding; |
24 | | -import com.google.devtools.build.lib.vfs.AbstractFileSystem; |
25 | 24 | import com.google.devtools.build.lib.vfs.DigestHashFunction; |
26 | 25 | import com.google.devtools.build.lib.vfs.Dirent; |
| 26 | +import com.google.devtools.build.lib.vfs.DiskBackedFileSystem; |
27 | 27 | import com.google.devtools.build.lib.vfs.FileStatus; |
28 | 28 | import com.google.devtools.build.lib.vfs.FileSymlinkLoopException; |
29 | 29 | import com.google.devtools.build.lib.vfs.Path; |
30 | 30 | import com.google.devtools.build.lib.vfs.PathFragment; |
31 | 31 | import com.google.devtools.build.lib.vfs.SymlinkTargetType; |
32 | 32 | import java.io.File; |
33 | | -import java.io.FileInputStream; |
34 | | -import java.io.FileNotFoundException; |
35 | | -import java.io.FileOutputStream; |
36 | 33 | import java.io.IOException; |
37 | | -import java.io.InputStream; |
38 | | -import java.io.OutputStream; |
39 | 34 | import java.util.ArrayDeque; |
40 | 35 | import java.util.Collection; |
41 | 36 | import javax.annotation.Nullable; |
42 | 37 |
|
43 | | -/** This class implements the FileSystem interface using direct calls to the UNIX filesystem. */ |
| 38 | +/** |
| 39 | + * A disk-backed filesystem suitable for Unix systems, implemented using a mix of JNI and standard |
| 40 | + * library calls. |
| 41 | + */ |
44 | 42 | @ThreadSafe |
45 | | -public class UnixFileSystem extends AbstractFileSystem { |
| 43 | +public class UnixFileSystem extends DiskBackedFileSystem { |
46 | 44 | protected final String hashAttributeName; |
47 | 45 |
|
48 | 46 | public UnixFileSystem(DigestHashFunction hashFunction, String hashAttributeName) { |
@@ -441,80 +439,4 @@ public File getIoFile(PathFragment path) { |
441 | 439 | public java.nio.file.Path getNioPath(PathFragment path) { |
442 | 440 | return java.nio.file.Path.of(StringEncoding.internalToPlatform(path.getPathString())); |
443 | 441 | } |
444 | | - |
445 | | - @Override |
446 | | - protected InputStream createFileInputStream(PathFragment path) throws IOException { |
447 | | - return new FileInputStream(StringEncoding.internalToPlatform(path.getPathString())); |
448 | | - } |
449 | | - |
450 | | - protected OutputStream createFileOutputStream(PathFragment path, boolean append) |
451 | | - throws FileNotFoundException { |
452 | | - return createFileOutputStream(path, append, /* internal= */ false); |
453 | | - } |
454 | | - |
455 | | - @Override |
456 | | - protected OutputStream createFileOutputStream(PathFragment path, boolean append, boolean internal) |
457 | | - throws FileNotFoundException { |
458 | | - String name = path.getPathString(); |
459 | | - var profiler = Profiler.instance(); |
460 | | - if (!internal |
461 | | - && profiler.isActive() |
462 | | - && (profiler.isProfiling(ProfilerTask.VFS_WRITE) |
463 | | - || profiler.isProfiling(ProfilerTask.VFS_OPEN))) { |
464 | | - long startTime = Profiler.instance().nanoTimeMaybe(); |
465 | | - var comp = Blocker.begin(); |
466 | | - try { |
467 | | - return new ProfiledFileOutputStream(name, /* append= */ append); |
468 | | - } finally { |
469 | | - Blocker.end(comp); |
470 | | - profiler.logSimpleTask(startTime, ProfilerTask.VFS_OPEN, name); |
471 | | - } |
472 | | - } else { |
473 | | - var comp = Blocker.begin(); |
474 | | - try { |
475 | | - return new FileOutputStream(StringEncoding.internalToPlatform(name), /* append= */ append); |
476 | | - } finally { |
477 | | - Blocker.end(comp); |
478 | | - } |
479 | | - } |
480 | | - } |
481 | | - |
482 | | - private static final class ProfiledFileOutputStream extends FileOutputStream { |
483 | | - private final String name; |
484 | | - |
485 | | - private ProfiledFileOutputStream(String name, boolean append) throws FileNotFoundException { |
486 | | - super(StringEncoding.internalToPlatform(name), append); |
487 | | - this.name = name; |
488 | | - } |
489 | | - |
490 | | - @Override |
491 | | - public void write(int b) throws IOException { |
492 | | - long startTime = Profiler.instance().nanoTimeMaybe(); |
493 | | - try { |
494 | | - super.write(b); |
495 | | - } finally { |
496 | | - Profiler.instance().logSimpleTask(startTime, ProfilerTask.VFS_WRITE, name); |
497 | | - } |
498 | | - } |
499 | | - |
500 | | - @Override |
501 | | - public void write(byte[] b) throws IOException { |
502 | | - long startTime = Profiler.instance().nanoTimeMaybe(); |
503 | | - try { |
504 | | - super.write(b); |
505 | | - } finally { |
506 | | - Profiler.instance().logSimpleTask(startTime, ProfilerTask.VFS_WRITE, name); |
507 | | - } |
508 | | - } |
509 | | - |
510 | | - @Override |
511 | | - public void write(byte[] b, int off, int len) throws IOException { |
512 | | - long startTime = Profiler.instance().nanoTimeMaybe(); |
513 | | - try { |
514 | | - super.write(b, off, len); |
515 | | - } finally { |
516 | | - Profiler.instance().logSimpleTask(startTime, ProfilerTask.VFS_WRITE, name); |
517 | | - } |
518 | | - } |
519 | | - } |
520 | 442 | } |
0 commit comments