/** * @return {@code True} if this is a directory. */ public boolean isDirectory() { return !isFile(); }
@Override public IgfsSecondaryInputStreamDescriptor onSuccess( Map<IgfsPath, IgfsEntryInfo> infos) throws Exception { IgfsEntryInfo info = infos.get(path); if (info == null) throw fsException(new IgfsPathNotFoundException("File not found: " + path)); if (!info.isFile()) throw fsException(new IgfsPathIsDirectoryException("Failed to open file " + "(not a file): " + path)); return new IgfsSecondaryInputStreamDescriptor(infos.get(path), lazySecondaryReader(fs, path, bufSize)); }
/** * Create directory and it's parents. * * @param pathIds Path IDs. * @param lockInfos Lock infos. * @param dirProps Directory properties. * @return Result or {@code} if the first parent already contained child with the same name. * @throws IgniteCheckedException If failed. */ @Nullable IgfsPathsCreateResult createDirectory(IgfsPathIds pathIds, Map<IgniteUuid, IgfsEntryInfo> lockInfos, Map<String, String> dirProps) throws IgniteCheckedException { // Check if entry we are going to write to is directory. if (lockInfos.get(pathIds.lastExistingId()).isFile()) throw new IgfsParentNotDirectoryException("Failed to create directory (parent " + "element is not a directory)"); return createFileOrDirectory(true, pathIds, lockInfos, dirProps, null, 0, null, false, null, null); }
/** * Create file and all it's parents. * * @param pathIds Paths IDs. * @param lockInfos Lock infos. * @param dirProps Directory properties. * @param fileProps File propertris. * @param blockSize Block size. * @param affKey Affinity key (optional) * @param evictExclude Evict exclude flag. * @param secondaryCtx Secondary file system create context. * @param secondaryOutHolder Holder for the secondary output stream. * @return Result or {@code} if the first parent already contained child with the same name. * @throws IgniteCheckedException If failed. */ @Nullable private IgfsPathsCreateResult createFile(IgfsPathIds pathIds, Map<IgniteUuid, IgfsEntryInfo> lockInfos, Map<String, String> dirProps, Map<String, String> fileProps, int blockSize, @Nullable IgniteUuid affKey, boolean evictExclude, @Nullable IgfsSecondaryFileSystemCreateContext secondaryCtx, @Nullable T1<OutputStream> secondaryOutHolder) throws IgniteCheckedException{ // Check if entry we are going to write to is directory. if (lockInfos.get(pathIds.lastExistingId()).isFile()) throw new IgfsParentNotDirectoryException("Failed to open file for write " + "(parent element is not a directory): " + pathIds.path()); return createFileOrDirectory(false, pathIds, lockInfos, dirProps, fileProps, blockSize, affKey, evictExclude, secondaryCtx, secondaryOutHolder); }
/** * Delete file's data from data cache. * * @param fileInfo File details to remove data for. * @return Delete future that will be completed when file is actually erased. */ public IgniteInternalFuture<Object> delete(IgfsEntryInfo fileInfo) { if (!fileInfo.isFile()) { if (log.isDebugEnabled()) log.debug("Cannot delete content of not-data file: " + fileInfo); return new GridFinishedFuture<>(); } else return delWorker.deleteAsync(fileInfo); }
assert fileInfo.isFile();
/** * Constructs file output stream. * * @param igfsCtx IGFS context. * @param path Path to stored file. * @param fileInfo File info to write binary data to. * @param bufSize The size of the buffer to be used. * @param mode Grid IGFS mode. * @param batch Optional secondary file system batch. */ IgfsOutputStreamImpl(IgfsContext igfsCtx, IgfsPath path, IgfsEntryInfo fileInfo, int bufSize, IgfsMode mode, @Nullable IgfsFileWorkerBatch batch) { super(igfsCtx, path, bufSize, batch); assert fileInfo != null && fileInfo.isFile() : "Unexpected file info: " + fileInfo; assert mode != null && mode != PROXY && (mode == PRIMARY && batch == null || batch != null); // File hasn't been locked. if (fileInfo.lockId() == null) throw new IgfsException("Failed to acquire file lock (concurrently modified?): " + path); synchronized (mux) { this.fileInfo = fileInfo; this.mode = mode; streamRange = initialStreamRange(fileInfo); writeFut = igfsCtx.data().writeStart(fileInfo.id()); } }
if (info.isFile())
/** * Constructs directory info. * * @param path Path. * @param info Entry info. * @param globalGrpBlockSize Global group block size. */ public IgfsFileImpl(IgfsPath path, IgfsEntryInfo info, long globalGrpBlockSize) { A.notNull(path, "path"); A.notNull(info, "info"); this.path = path; fileId = info.id(); flags = IgfsUtils.flags(info.isDirectory(), info.isFile()); if (info.isFile()) { blockSize = info.blockSize(); len = info.length(); grpBlockSize = info.affinityKey() == null ? globalGrpBlockSize : info.length() == 0 ? globalGrpBlockSize : info.length(); } props = info.properties(); if (props == null) props = Collections.emptyMap(); accessTime = info.accessTime(); modificationTime = info.modificationTime(); }
if (!info.isFile()) throw fsException(new IgfsPathIsDirectoryException("Failed to open file (not a file): " + path));
@Override public Collection<IgfsBlockLocation> call() throws Exception { if (log.isDebugEnabled()) log.debug("Get affinity for file block [path=" + path + ", start=" + start + ", len=" + len + ']'); IgfsMode mode = resolveMode(path); if (mode == PROXY) return secondaryFs.affinity(path, start, len, maxLen); // Check memory first. IgfsEntryInfo info = meta.infoForPath(path); if (info == null && mode != PRIMARY) { assert IgfsUtils.isDualMode(mode); assert secondaryFs != null; // Synchronize info = meta.synchronizeFileDual(secondaryFs, path); } if (info == null) throw new IgfsPathNotFoundException("File not found: " + path); if (!info.isFile()) throw new IgfsPathIsDirectoryException("Failed to get affinity for path because it is not " + "a file: " + path); return data.affinity(info, start, len, maxLen); } });
@Override public Boolean call() throws Exception { if (log.isDebugEnabled()) log.debug("Deleting file [path=" + path + ", recursive=" + recursive + ']'); if (F.eq(IgfsPath.ROOT, path)) return false; IgfsMode mode = resolveMode(path); if (mode == PROXY) return secondaryFs.delete(path, recursive); boolean dual = IgfsUtils.isDualMode(mode); if (dual) await(path); IgfsDeleteResult res = meta.softDelete(path, recursive, dual ? secondaryFs : null); // Record event if needed. if (res.success() && res.info() != null) IgfsUtils.sendEvents(igfsCtx.kernalContext(), path, res.info().isFile() ? EVT_IGFS_FILE_DELETED : EVT_IGFS_DIR_DELETED); return res.success(); } });
if (!info.isFile()) throw new IgfsPathIsDirectoryException("Failed to open file for write." + path);
assert info.isFile() : "Failed to get affinity (not a file): " + info; assert start >= 0 : "Start position should not be negative: " + start; assert len >= 0 : "Part length should not be negative: " + len;
assert info.isFile();
if (!oldInfo.isFile()) throw new IgfsPathIsDirectoryException("Failed to create a file: " + path);
throw new IgfsPathNotFoundException("File not found: " + path); if (!info.isFile()) throw new IgfsPathIsDirectoryException("Failed to open file (not a file): " + path);
assertTrue(info.isFile()); assertNotNull(metaCache.get(info.id()));