termux-app

Форк
0
58 строк · 2.1 Кб
1
package com.termux.shared.file.filesystem;
2

3
import android.system.ErrnoException;
4
import android.system.Os;
5

6
import java.io.File;
7
import java.io.FileDescriptor;
8
import java.io.IOException;
9

10
public class NativeDispatcher {
11

12
    public static void stat(String filePath, FileAttributes fileAttributes) throws IOException {
13
        validateFileExistence(filePath);
14

15
        try {
16
            fileAttributes.loadFromStructStat(Os.stat(filePath));
17
        } catch (ErrnoException e) {
18
            throw new IOException("Failed to run Os.stat() on file at path \"" + filePath + "\": " + e.getMessage());
19
        }
20
    }
21

22
    public static void lstat(String filePath, FileAttributes fileAttributes) throws IOException {
23
        validateFileExistence(filePath);
24

25
        try {
26
            fileAttributes.loadFromStructStat(Os.lstat(filePath));
27
        } catch (ErrnoException e) {
28
            throw new IOException("Failed to run Os.lstat() on file at path \"" + filePath + "\": " + e.getMessage());
29
        }
30
    }
31

32
    public static void fstat(FileDescriptor fileDescriptor, FileAttributes fileAttributes) throws IOException {
33
        validateFileDescriptor(fileDescriptor);
34

35
        try {
36
            fileAttributes.loadFromStructStat(Os.fstat(fileDescriptor));
37
        } catch (ErrnoException e) {
38
            throw new IOException("Failed to run Os.fstat() on file descriptor \"" + fileDescriptor.toString() + "\": " + e.getMessage());
39
        }
40
    }
41

42
    public static void validateFileExistence(String filePath) throws IOException {
43
        if (filePath == null || filePath.isEmpty()) throw new IOException("The path is null or empty");
44

45
        File file = new File(filePath);
46

47
        //if (!file.exists())
48
        //    throw new IOException("No such file or directory: \"" + filePath + "\"");
49
    }
50

51
    public static void validateFileDescriptor(FileDescriptor fileDescriptor) throws IOException {
52
        if (fileDescriptor == null) throw new IOException("The file descriptor is null");
53

54
        if (!fileDescriptor.valid())
55
            throw new IOException("No such file descriptor: \"" + fileDescriptor.toString() + "\"");
56
    }
57

58
}
59

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.