use of com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile in project intellij-community by JetBrains.
the class LocalFileSystemBase method createChildDirectory.
@Override
@NotNull
public VirtualFile createChildDirectory(Object requestor, @NotNull final VirtualFile parent, @NotNull final String dir) throws IOException {
if (!isValidName(dir)) {
throw new IOException(VfsBundle.message("directory.invalid.name.error", dir));
}
if (!parent.exists() || !parent.isDirectory()) {
throw new IOException(VfsBundle.message("vfs.target.not.directory.error", parent.getPath()));
}
if (parent.findChild(dir) != null) {
throw new IOException(VfsBundle.message("vfs.target.already.exists.error", parent.getPath() + "/" + dir));
}
File ioParent = convertToIOFile(parent);
if (!ioParent.isDirectory()) {
throw new IOException(VfsBundle.message("target.not.directory.error", ioParent.getPath()));
}
if (!auxCreateDirectory(parent, dir)) {
File ioDir = new File(ioParent, dir);
if (!(ioDir.mkdirs() || ioDir.isDirectory())) {
throw new IOException(VfsBundle.message("new.directory.failed.error", ioDir.getPath()));
}
}
auxNotifyCompleted(handler -> handler.createDirectory(parent, dir));
return new FakeVirtualFile(parent, dir);
}
use of com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile in project intellij-community by JetBrains.
the class RefreshWorker method partialDirRefresh.
private void partialDirRefresh(NewVirtualFileSystem fs, TObjectHashingStrategy<String> strategy, VirtualDirectoryImpl dir) {
while (true) {
// obtaining directory snapshot
List<VirtualFile> cached;
List<String> wanted;
AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
try {
cached = dir.getCachedChildren();
wanted = dir.getSuspiciousNames();
} finally {
token.finish();
}
OpenTHashSet<String> actualNames = null;
if (!fs.isCaseSensitive()) {
actualNames = new OpenTHashSet<>(strategy, VfsUtil.filterNames(fs.list(dir)));
}
if (LOG.isTraceEnabled()) {
LOG.trace("cached=" + cached + " actual=" + actualNames);
LOG.trace("suspicious=" + wanted);
}
// reading children attributes
List<Pair<VirtualFile, FileAttributes>> existingMap = ContainerUtil.newArrayListWithCapacity(cached.size());
for (VirtualFile child : cached) {
checkCancelled(dir);
existingMap.add(pair(child, fs.getAttributes(child)));
}
List<Pair<String, FileAttributes>> wantedMap = ContainerUtil.newArrayListWithCapacity(wanted.size());
for (String name : wanted) {
if (name.isEmpty())
continue;
checkCancelled(dir);
wantedMap.add(pair(name, fs.getAttributes(new FakeVirtualFile(dir, name))));
}
// generating events unless a directory was changed in between
token = ApplicationManager.getApplication().acquireReadActionLock();
try {
if (!cached.equals(dir.getCachedChildren()) || !wanted.equals(dir.getSuspiciousNames())) {
if (LOG.isDebugEnabled())
LOG.debug("retry: " + dir);
continue;
}
for (Pair<VirtualFile, FileAttributes> pair : existingMap) {
VirtualFile child = pair.first;
FileAttributes childAttributes = pair.second;
if (childAttributes != null) {
checkAndScheduleChildRefresh(dir, child, childAttributes);
checkAndScheduleFileNameChange(actualNames, child);
} else {
scheduleDeletion(child);
}
}
for (Pair<String, FileAttributes> pair : wantedMap) {
String name = pair.first;
FileAttributes childAttributes = pair.second;
if (childAttributes != null) {
scheduleCreation(dir, name, childAttributes.isDirectory(), false);
}
}
break;
} finally {
token.finish();
}
}
}
use of com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile in project intellij-community by JetBrains.
the class RefreshWorker method fullDirRefresh.
private void fullDirRefresh(NewVirtualFileSystem fs, PersistentFS persistence, TObjectHashingStrategy<String> strategy, VirtualDirectoryImpl dir) {
while (true) {
// obtaining directory snapshot
String[] currentNames;
VirtualFile[] children;
AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
try {
currentNames = persistence.list(dir);
children = dir.getChildren();
} finally {
token.finish();
}
// reading children attributes
String[] upToDateNames = VfsUtil.filterNames(fs.list(dir));
Set<String> newNames = newTroveSet(strategy, upToDateNames);
ContainerUtil.removeAll(newNames, currentNames);
Set<String> deletedNames = newTroveSet(strategy, currentNames);
ContainerUtil.removeAll(deletedNames, upToDateNames);
OpenTHashSet<String> actualNames = null;
if (!fs.isCaseSensitive()) {
actualNames = new OpenTHashSet<>(strategy, upToDateNames);
}
if (LOG.isTraceEnabled())
LOG.trace("current=" + Arrays.toString(currentNames) + " +" + newNames + " -" + deletedNames);
List<Pair<String, FileAttributes>> addedMap = ContainerUtil.newArrayListWithCapacity(newNames.size());
for (String name : newNames) {
checkCancelled(dir);
addedMap.add(pair(name, fs.getAttributes(new FakeVirtualFile(dir, name))));
}
List<Pair<VirtualFile, FileAttributes>> updatedMap = ContainerUtil.newArrayListWithCapacity(children.length);
for (VirtualFile child : children) {
if (deletedNames.contains(child.getName()))
continue;
checkCancelled(dir);
updatedMap.add(pair(child, fs.getAttributes(child)));
}
// generating events unless a directory was changed in between
token = ApplicationManager.getApplication().acquireReadActionLock();
try {
if (!Arrays.equals(currentNames, persistence.list(dir)) || !Arrays.equals(children, dir.getChildren())) {
if (LOG.isDebugEnabled())
LOG.debug("retry: " + dir);
continue;
}
for (String name : deletedNames) {
scheduleDeletion(dir.findChild(name));
}
for (Pair<String, FileAttributes> pair : addedMap) {
String name = pair.first;
FileAttributes childAttributes = pair.second;
if (childAttributes != null) {
scheduleCreation(dir, name, childAttributes.isDirectory(), false);
} else {
LOG.warn("[+] fs=" + fs + " dir=" + dir + " name=" + name);
}
}
for (Pair<VirtualFile, FileAttributes> pair : updatedMap) {
VirtualFile child = pair.first;
FileAttributes childAttributes = pair.second;
if (childAttributes != null) {
checkAndScheduleChildRefresh(dir, child, childAttributes);
checkAndScheduleFileNameChange(actualNames, child);
} else {
LOG.warn("[x] fs=" + fs + " dir=" + dir + " name=" + child.getName());
scheduleDeletion(child);
}
}
break;
} finally {
token.finish();
}
}
}
use of com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile in project intellij-community by JetBrains.
the class LocalFileSystemBase method createChildFile.
@NotNull
@Override
public VirtualFile createChildFile(Object requestor, @NotNull final VirtualFile parent, @NotNull final String file) throws IOException {
if (!isValidName(file)) {
throw new IOException(VfsBundle.message("file.invalid.name.error", file));
}
if (!parent.exists() || !parent.isDirectory()) {
throw new IOException(VfsBundle.message("vfs.target.not.directory.error", parent.getPath()));
}
if (parent.findChild(file) != null) {
throw new IOException(VfsBundle.message("vfs.target.already.exists.error", parent.getPath() + "/" + file));
}
File ioParent = convertToIOFile(parent);
if (!ioParent.isDirectory()) {
throw new IOException(VfsBundle.message("target.not.directory.error", ioParent.getPath()));
}
if (!auxCreateFile(parent, file)) {
File ioFile = new File(ioParent, file);
if (!FileUtil.createIfDoesntExist(ioFile)) {
throw new IOException(VfsBundle.message("new.file.failed.error", ioFile.getPath()));
}
}
auxNotifyCompleted(handler -> handler.createFile(parent, file));
return new FakeVirtualFile(parent, file);
}
use of com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile in project intellij-community by JetBrains.
the class LocalFileSystemBase method copyFile.
@NotNull
@Override
public VirtualFile copyFile(Object requestor, @NotNull final VirtualFile file, @NotNull final VirtualFile newParent, @NotNull final String copyName) throws IOException {
if (!isValidName(copyName)) {
throw new IOException(VfsBundle.message("file.invalid.name.error", copyName));
}
if (!file.exists()) {
throw new IOException(VfsBundle.message("vfs.file.not.exist.error", file.getPath()));
}
if (!newParent.exists() || !newParent.isDirectory()) {
throw new IOException(VfsBundle.message("vfs.target.not.directory.error", newParent.getPath()));
}
if (newParent.findChild(copyName) != null) {
throw new IOException(VfsBundle.message("vfs.target.already.exists.error", newParent.getPath() + "/" + copyName));
}
FileAttributes attributes = getAttributes(file);
if (attributes == null) {
throw new FileNotFoundException(VfsBundle.message("file.not.exist.error", file.getPath()));
}
if (attributes.isSpecial()) {
throw new FileNotFoundException("Not a file: " + file);
}
File ioParent = convertToIOFile(newParent);
if (!ioParent.isDirectory()) {
throw new IOException(VfsBundle.message("target.not.directory.error", ioParent.getPath()));
}
File ioTarget = new File(ioParent, copyName);
if (ioTarget.exists()) {
throw new IOException(VfsBundle.message("target.already.exists.error", ioTarget.getPath()));
}
if (!auxCopy(file, newParent, copyName)) {
try {
File ioFile = convertToIOFile(file);
FileUtil.copyFileOrDir(ioFile, ioTarget, attributes.isDirectory());
} catch (IOException e) {
FileUtil.delete(ioTarget);
throw e;
}
}
auxNotifyCompleted(handler -> handler.copy(file, newParent, copyName));
return new FakeVirtualFile(newParent, copyName);
}
Aggregations