Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
Ulf Adams | 8afbd3c | 2017-02-28 10:42:48 +0000 | [diff] [blame] | 14 | package com.google.devtools.build.lib.unix; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 15 | |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 16 | import static com.google.common.truth.Truth.assertThat; |
michajlo | 660d17f | 2020-03-27 09:01:57 -0700 | [diff] [blame] | 17 | import static org.junit.Assert.assertThrows; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 18 | |
ccalvarin | 94c171c | 2018-08-16 15:42:19 -0700 | [diff] [blame] | 19 | import com.google.devtools.build.lib.vfs.DigestHashFunction; |
Ulf Adams | 8afbd3c | 2017-02-28 10:42:48 +0000 | [diff] [blame] | 20 | import com.google.devtools.build.lib.vfs.FileSystem; |
| 21 | import com.google.devtools.build.lib.vfs.FileSystemUtils; |
| 22 | import com.google.devtools.build.lib.vfs.Path; |
| 23 | import com.google.devtools.build.lib.vfs.SymlinkAwareFileSystemTest; |
| 24 | import com.google.devtools.build.lib.vfs.Symlinks; |
| 25 | import java.io.IOException; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 26 | import org.junit.Test; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 27 | |
Ulf Adams | 8afbd3c | 2017-02-28 10:42:48 +0000 | [diff] [blame] | 28 | /** Tests for the {@link com.google.devtools.build.lib.unix.UnixFileSystem} class. */ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 29 | public class UnixFileSystemTest extends SymlinkAwareFileSystemTest { |
| 30 | |
| 31 | @Override |
ccalvarin | 94c171c | 2018-08-16 15:42:19 -0700 | [diff] [blame] | 32 | protected FileSystem getFreshFileSystem(DigestHashFunction digestHashFunction) { |
Ed Schouten | 05650ff | 2020-09-17 10:01:25 -0700 | [diff] [blame] | 33 | return new UnixFileSystem(digestHashFunction, /*hashAttributeName=*/ ""); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public void destroyFileSystem(FileSystem fileSystem) { |
| 38 | // Nothing. |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | protected void expectNotFound(Path path) throws IOException { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 43 | assertThat(path.statIfFound()).isNull(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | // Most tests are just inherited from FileSystemTest. |
| 47 | |
| 48 | @Test |
| 49 | public void testCircularSymlinkFound() throws Exception { |
| 50 | Path linkA = absolutize("link-a"); |
| 51 | Path linkB = absolutize("link-b"); |
| 52 | linkA.createSymbolicLink(linkB); |
| 53 | linkB.createSymbolicLink(linkA); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 54 | assertThat(linkA.exists(Symlinks.FOLLOW)).isFalse(); |
jcater | 6cfebc9 | 2019-05-01 12:40:08 -0700 | [diff] [blame] | 55 | assertThrows(IOException.class, () -> linkA.statIfFound(Symlinks.FOLLOW)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 56 | } |
Nathan Harmata | d8b6ff2 | 2015-10-20 21:54:34 +0000 | [diff] [blame] | 57 | |
| 58 | @Test |
| 59 | public void testIsSpecialFile() throws Exception { |
| 60 | Path regular = absolutize("regular"); |
| 61 | Path fifo = absolutize("fifo"); |
| 62 | FileSystemUtils.createEmptyFile(regular); |
Lukacs Berki | 7ecb2ce | 2016-01-26 15:40:42 +0000 | [diff] [blame] | 63 | NativePosixFiles.mkfifo(fifo.toString(), 0777); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 64 | assertThat(regular.isFile()).isTrue(); |
| 65 | assertThat(regular.isSpecialFile()).isFalse(); |
| 66 | assertThat(regular.stat().isFile()).isTrue(); |
| 67 | assertThat(regular.stat().isSpecialFile()).isFalse(); |
| 68 | assertThat(fifo.isFile()).isTrue(); |
| 69 | assertThat(fifo.isSpecialFile()).isTrue(); |
| 70 | assertThat(fifo.stat().isFile()).isTrue(); |
| 71 | assertThat(fifo.stat().isSpecialFile()).isTrue(); |
Nathan Harmata | d8b6ff2 | 2015-10-20 21:54:34 +0000 | [diff] [blame] | 72 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 73 | } |