Skip to content

Commit

Permalink
use canMkdir replace isOwner in LocalFileSystem,and when io not proxy…
Browse files Browse the repository at this point in the history
…, setPermission as parent
  • Loading branch information
lunescode committed Oct 12, 2021
1 parent 89cde7d commit 1af027a
Showing 1 changed file with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public boolean mkdirs(FsPath dest) throws IOException {
dirsToMake.push(parent);
parent = parent.getParentFile();
}
if(!isOwner(parent.getPath())) {
if(!canMkdir(new FsPath(parent.getPath()))) {
throw new IOException("only owner can mkdir path " + path);
}
while (!dirsToMake.empty()) {
Expand All @@ -157,6 +157,19 @@ public boolean mkdirs(FsPath dest) throws IOException {
return true;
}

public boolean canMkdir(FsPath destParentDir) throws IOException {
if (!StorageUtils.isIOProxy()){
LOG.debug("io not proxy, not check ownerer, just check if hava write permission ");
return this.canWrite(destParentDir);
}else{
LOG.info("io proxy, check owner ");
if(!isOwner(destParentDir.getPath())) {
throw new IOException("current user:" + user + ", parentPath:"+ destParentDir.getPath() +", only owner can mkdir path " + destParentDir);
}
}
return false;
}

@Override
public boolean copy(String origin, String dest) throws IOException {
File file = new File(dest);
Expand All @@ -183,17 +196,29 @@ public boolean copy(String origin, String dest) throws IOException {
@Override
public boolean setPermission(FsPath dest, String permission) throws IOException {
if (!StorageUtils.isIOProxy()){
LOG.info("io not proxy, setPermission skip");
LOG.info("io not proxy, setPermission as parent.");
try {
PosixFileAttributes attr = Files.readAttributes(Paths.get(dest.getParent().getPath()), PosixFileAttributes.class);
LOG.debug("parent permissions: attr: " + attr);
Files.setPosixFilePermissions(Paths.get(dest.getPath()), attr.permissions());

}catch (NoSuchFileException e){
LOG.error("File or folder does not exist or file name is garbled(文件或者文件夹不存在或者文件名乱码)",e);
throw new StorageWarnException(51001,e.getMessage());
}
return true;

}
String path = dest.getPath();
if(StringUtils.isNumeric(permission)) {
permission = FsPath.permissionFormatted(permission);
}
Files.setPosixFilePermissions(Paths.get(path), PosixFilePermissions.fromString(permission));
return true;

}


@Override
public FsPathListWithError listPathWithError(FsPath path) throws IOException {
File file = new File(path.getPath());
Expand Down Expand Up @@ -402,4 +427,4 @@ private String getOwner(String path) throws IOException {
Files.readAttributes(Paths.get(path), PosixFileAttributes.class);
return attr.owner().getName();
}
}
}

0 comments on commit 1af027a

Please sign in to comment.