Skip to content

Commit

Permalink
fix: listStatus support directoryFirstEnabled switch. (#135)
Browse files Browse the repository at this point in the history
(cherry picked from commit 5f157fd)
  • Loading branch information
suninsky authored Feb 21, 2024
1 parent e141e95 commit 8006bc9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/java/org/apache/hadoop/fs/CosNFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class CosNFileSystem extends FileSystem {
// so in this situation, we need disable this duplicate folder/file check in CosN
private boolean createOpCheckExistFile = true;

private boolean directoryFirstEnabled;

// todo: flink or some other case must replace with inner structure.
public CosNFileSystem() {
}
Expand Down Expand Up @@ -231,6 +233,8 @@ public void rejectedExecution(Runnable r,

this.symbolicLinkSizeThreshold = this.getConf().getInt(
CosNConfigKeys.COSN_SYMBOLIC_SIZE_THRESHOLD, CosNConfigKeys.DEFAULT_COSN_SYMBOLIC_SIZE_THRESHOLD);
this.directoryFirstEnabled = this.getConf().getBoolean(CosNConfigKeys.COSN_FILESTATUS_DIR_FIRST_ENABLED,
CosNConfigKeys.DEFAULT_FILESTATUS_DIR_FIRST_ENABLED);
}

@Override
Expand Down Expand Up @@ -679,8 +683,12 @@ public FileStatus[] listStatus(Path f) throws IOException {
Path subPath = keyToPath(commonPrefix.getKey());
String relativePath =
pathUri.relativize(subPath.toUri()).getPath();
status.add(newDirectory(commonPrefix, new Path(absolutePath,
relativePath)));
FileStatus directory = newDirectory(commonPrefix, new Path(absolutePath, relativePath));
if (this.directoryFirstEnabled) {
// 如果开启目录优先,需要先调用remove删除可能存在的同名文件,避免目录无法add
status.remove(directory);
}
status.add(directory);
}
priorLastKey = listing.getPriorLastKey();
} while (priorLastKey != null);
Expand Down

0 comments on commit 8006bc9

Please sign in to comment.