mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 10:45:23 +08:00
Added: Add FileType.SOCKET
support and add FileUtils.deleteSocketFile()
function
This commit is contained in:
@@ -1116,6 +1116,21 @@ public class FileUtils {
|
|||||||
return deleteFile(label, filePath, ignoreNonExistentFile, false, FileType.SYMLINK.getValue());
|
return deleteFile(label, filePath, ignoreNonExistentFile, false, FileType.SYMLINK.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete socket file at path.
|
||||||
|
*
|
||||||
|
* This function is a wrapper for {@link #deleteFile(String, String, boolean, boolean, int)}.
|
||||||
|
*
|
||||||
|
* @param label The optional label for file to delete. This can optionally be {@code null}.
|
||||||
|
* @param filePath The {@code path} for file to delete.
|
||||||
|
* @param ignoreNonExistentFile The {@code boolean} that decides if it should be considered an
|
||||||
|
* error if file to deleted doesn't exist.
|
||||||
|
* @return Returns the {@code error} if deletion was not successful, otherwise {@code null}.
|
||||||
|
*/
|
||||||
|
public static Error deleteSocketFile(String label, final String filePath, final boolean ignoreNonExistentFile) {
|
||||||
|
return deleteFile(label, filePath, ignoreNonExistentFile, false, FileType.SOCKET.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete regular, directory or symlink file at path.
|
* Delete regular, directory or symlink file at path.
|
||||||
*
|
*
|
||||||
|
@@ -202,6 +202,10 @@ public class FileAttributes {
|
|||||||
return ((st_mode & UnixConstants.S_IFMT) == UnixConstants.S_IFIFO);
|
return ((st_mode & UnixConstants.S_IFMT) == UnixConstants.S_IFIFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSocket() {
|
||||||
|
return ((st_mode & UnixConstants.S_IFMT) == UnixConstants.S_IFSOCK);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isBlock() {
|
public boolean isBlock() {
|
||||||
return ((st_mode & UnixConstants.S_IFMT) == UnixConstants.S_IFBLK);
|
return ((st_mode & UnixConstants.S_IFMT) == UnixConstants.S_IFBLK);
|
||||||
}
|
}
|
||||||
|
@@ -3,14 +3,15 @@ package com.termux.shared.file.filesystem;
|
|||||||
/** The {@link Enum} that defines file types. */
|
/** The {@link Enum} that defines file types. */
|
||||||
public enum FileType {
|
public enum FileType {
|
||||||
|
|
||||||
NO_EXIST("no exist", 0), // 0000000
|
NO_EXIST("no exist", 0), // 00000000
|
||||||
REGULAR("regular", 1), // 0000001
|
REGULAR("regular", 1), // 00000001
|
||||||
DIRECTORY("directory", 2), // 0000010
|
DIRECTORY("directory", 2), // 00000010
|
||||||
SYMLINK("symlink", 4), // 0000100
|
SYMLINK("symlink", 4), // 00000100
|
||||||
CHARACTER("character", 8), // 0001000
|
SOCKET("socket", 8), // 00001000
|
||||||
FIFO("fifo", 16), // 0010000
|
CHARACTER("character", 16), // 00010000
|
||||||
BLOCK("block", 32), // 0100000
|
FIFO("fifo", 32), // 00100000
|
||||||
UNKNOWN("unknown", 64); // 1000000
|
BLOCK("block", 64), // 01000000
|
||||||
|
UNKNOWN("unknown", 128); // 10000000
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int value;
|
private final int value;
|
||||||
|
@@ -104,6 +104,8 @@ public class FileTypes {
|
|||||||
return FileType.DIRECTORY;
|
return FileType.DIRECTORY;
|
||||||
else if (fileAttributes.isSymbolicLink())
|
else if (fileAttributes.isSymbolicLink())
|
||||||
return FileType.SYMLINK;
|
return FileType.SYMLINK;
|
||||||
|
else if (fileAttributes.isSocket())
|
||||||
|
return FileType.SOCKET;
|
||||||
else if (fileAttributes.isCharacter())
|
else if (fileAttributes.isCharacter())
|
||||||
return FileType.CHARACTER;
|
return FileType.CHARACTER;
|
||||||
else if (fileAttributes.isFifo())
|
else if (fileAttributes.isFifo())
|
||||||
|
@@ -88,6 +88,8 @@ public class UnixConstants {
|
|||||||
|
|
||||||
static final int S_IFLNK = OsConstants.S_IFLNK;
|
static final int S_IFLNK = OsConstants.S_IFLNK;
|
||||||
|
|
||||||
|
static final int S_IFSOCK = OsConstants.S_IFSOCK;
|
||||||
|
|
||||||
static final int S_IFCHR = OsConstants.S_IFCHR;
|
static final int S_IFCHR = OsConstants.S_IFCHR;
|
||||||
|
|
||||||
static final int S_IFBLK = OsConstants.S_IFBLK;
|
static final int S_IFBLK = OsConstants.S_IFBLK;
|
||||||
|
Reference in New Issue
Block a user