Package org.sonatype.nexus.proxy

Examples of org.sonatype.nexus.proxy.LocalStorageException


      throws LocalStorageException
  {
    boolean result = validFileUrl(url);

    if (!result) {
      throw new LocalStorageException("Invalid storage URL, not a file based one: " + url);
    }
  }
View Full Code Here


      log.trace("{} --> {}", request.getRequestPath(), result.getAbsoluteFile());
    }

    // to be foolproof, chrooting it
    if (!result.getAbsolutePath().startsWith(getBaseDir(repository, request).getAbsolutePath())) {
      throw new LocalStorageException("getFileFromBase() method evaluated directory wrongly in repository \""
          + repository.getName() + "\" (id=\"" + repository.getId() + "\")! baseDir="
          + getBaseDir(repository, request).getAbsolutePath() + ", target=" + result.getAbsolutePath());
    }
    else {
      return result;
View Full Code Here

        throw new ItemNotFoundException(reasonFor(request, repository,
            "Path %s not found in local storage of repository %s", request.getRequestPath(),
            RepositoryStringUtils.getHumanizedNameString(repository)), e);
      }
      catch (IOException e) {
        throw new LocalStorageException("Exception during reading up an item from FS storage!", e);
      }
    }
    else {
      throw new ItemNotFoundException(reasonFor(request, repository,
          "Path %s not found in local storage of repository %s", request.getRequestPath(),
View Full Code Here

          getLinkPersister().writeLinkContent((StorageLinkItem) item, bos);
        }
        catch (IOException e) {
          // should not happen, look at implementation
          // we will handle here two byte array backed streams!
          throw new LocalStorageException("Problem ", e);
        }

        cl = new ByteArrayContentLocator(bos.toByteArray(), "text/xml");
      }

      target = getFileFromBase(repository, item.getResourceStoreRequest());

      getFSPeer().storeItem(repository, getBaseDir(repository, item.getResourceStoreRequest()), item, target, cl);
    }
    finally {
      // NEXUS-5468: Ensure that in case of file item with prepared content
      // (typically those coming from RRS, as the content is actually wrapped HTTP response body, hence not reusable)
      // get closed irrelevant of the actual outcome. If all went right, stream was already closed,
      // and we will be "punished" by one extra (redundant) call to Closeable#close().
      if (originalContentLocator instanceof Closeable) {
        IOUtils.closeQuietly((Closeable) originalContentLocator);
      }
    }

    if (item instanceof StorageFileItem) {
      // replace content locator transparently, if we just consumed a non-reusable one
      // Hint: in general, those items coming from user uploads or remote proxy caching requests are non
      // reusable ones
      ((StorageFileItem) item).setContentLocator(new FileContentLocator(target,
          ((StorageFileItem) item).getMimeType()));
    }

    final ContentLocator mdis =
        item instanceof StorageFileItem ? ((StorageFileItem) item).getContentLocator() : null;

    try {
      repository.getAttributesHandler().storeAttributes(item, mdis);
    }
    catch (IOException e) {
      throw new LocalStorageException("Cannot store attributes!", e);
    }
  }
View Full Code Here

    try {
      repository.getAttributesHandler().deleteAttributes(uid);
    }
    catch (IOException e) {
      throw new LocalStorageException("Cannot delete attributes!", e);
    }

    File target = getFileFromBase(repository, request);

    getFSPeer().shredItem(repository, getBaseDir(repository, request), request, target);
View Full Code Here

      // to not wrap these, they are IOEx subclass
      throw e;
    }
    catch (IOException e) {
      // cleanup
      throw new LocalStorageException("Cannot store attributes!", e);
    }
  }
View Full Code Here

    try {
      return requestRepositoryMapper.getMappedRepositories(this, request, members);
    }
    catch (NoSuchResourceStoreException e) {
      throw new LocalStorageException(e);
    }
  }
View Full Code Here

          Files.deleteIfExists(hiddenTarget.toPath());
        }
        catch (IOException e1) {
          // best effort to delete, we already have what to throw
        }
        throw new LocalStorageException(String.format(
            "Got exception during storing on path \"%s\" (while writing to hiddenTarget: \"%s\")",
            item.getRepositoryItemUid().toString(), hiddenTarget.getAbsolutePath()), e);
      }

      // NEXUS-4550: Part Two, moving the "hidden" (temp) file to final location
      // In case of error cleaning up both files
      // Locking is needed, AbstractRepository got shared lock only for destination

      // NEXUS-4550: FSPeer is the one that handles the rename in case of FS LS,
      // so we need here to claim exclusive lock on actual UID to perform the rename
      final RepositoryItemUidLock uidLock = item.getRepositoryItemUid().getLock();
      uidLock.lock(Action.create);

      try {
        handleRenameOperation(hiddenTarget, target);
        target.setLastModified(item.getModified());
      }
      catch (IOException e) {
        // if we ARE NOT handling attributes, do proper cleanup in case of IOEx
        // if we ARE handling attributes, leave backups in case of IOEx
        final boolean isCleanupNeeded =
            !item.getRepositoryItemUid().getBooleanAttributeValue(IsItemAttributeMetacontentAttribute.class);

        if (target != null && (isCleanupNeeded ||
            // NEXUS-4871 prevent zero length/corrupt files
            target.length() == 0)) {
          try {
            Files.delete(target.toPath());
          }
          catch (IOException e1) {
            log.warn("Could not delete file: " + target.getAbsolutePath(), e);
          }
        }

        if (hiddenTarget != null && (isCleanupNeeded ||
            // NEXUS-4871 prevent zero length/corrupt files
            hiddenTarget.length() == 0)) {
          try {
            Files.delete(hiddenTarget.toPath());
          }
          catch (IOException e1) {
            log.warn("Could not delete file: " + target.getAbsolutePath(), e);
          }
        }

        if (!isCleanupNeeded) {
          log.warn(
              "No cleanup done for error that happened while trying to save attibutes of item {}, the backup is left as {}!",
              item.getRepositoryItemUid().toString(), hiddenTarget.getAbsolutePath());
        }

        throw new LocalStorageException(String.format(
            "Got exception during storing on path \"%s\" (while moving to final destination)",
            item.getRepositoryItemUid().toString()), e);
      }
      finally {
        uidLock.unlock();
View Full Code Here

            "Path %s not found in local storage of repository %s", request.getRequestPath(),
            RepositoryStringUtils.getHumanizedNameString(repository)));
      }
    }
    catch (IOException e) {
      throw new LocalStorageException(String.format(
          "Could not delete file in repository %s from path \"%s\"",
          RepositoryStringUtils.getHumanizedNameString(repository), target.getAbsolutePath()), e);
    }
  }
View Full Code Here

            "Path %s not found in local storage of repository %s", from.getRequestPath(),
            RepositoryStringUtils.getHumanizedNameString(repository)));
      }
    }
    catch (IOException e) {
      throw new LocalStorageException("Error during moveItem", e);
    }
  }
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.LocalStorageException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.