Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

NEXUS-4955 - expand the prefix when it is too short #349

Merged
merged 3 commits into from Mar 26, 2012
@@ -1,3 +1,15 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
package org.sonatype.nexus.configuration.application;
@cstamas

cstamas Mar 21, 2012

Contributor

? What's this?

@velo

velo Mar 21, 2012

Contributor

A missing header...

import static java.lang.String.format;
@@ -12,6 +12,8 @@
*/
package org.sonatype.nexus.proxy.storage.local.fs;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.io.File;
import java.io.FileFilter;
import java.io.FileOutputStream;
@@ -54,6 +56,8 @@
{
private static final String HIDDEN_TARGET_SUFFIX = ".nx-upload";
+ private static final String APPENDIX = "nx-tmp";
+
public boolean isReachable( Repository repository, ResourceStoreRequest request, File target )
throws LocalStorageException
{
@@ -318,9 +322,12 @@ else if ( target.isFile() )
protected File getHiddenTarget( final File target, final StorageItem item )
throws LocalStorageException
{
+ checkNotNull( target );
+
try
{
- return File.createTempFile( target.getName(), HIDDEN_TARGET_SUFFIX, target.getParentFile() );
+ // NEXUS-4955 add APPENDIX to make sure prefix is bigger the 3 chars
+ return File.createTempFile( target.getName() + APPENDIX, HIDDEN_TARGET_SUFFIX, target.getParentFile() );
}
catch ( IOException e )
{
@@ -0,0 +1,39 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.proxy.storage.local.fs;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.sonatype.sisu.litmus.testsupport.hamcrest.FileMatchers.exists;
+
+import java.io.File;
+
+import org.junit.Test;
+
+public class DefaultFSPeerTest
+{
+
+ @Test
+ public void testGetHiddenTarget()
+ throws Exception
+ {
+ File base = new File( "target/a/b/c/d" );
+ base.getParentFile().mkdirs();
+ base.createNewFile();
+
+ File created = new DefaultFSPeer().getHiddenTarget( base, null );
+ assertThat( created, notNullValue() );
+ assertThat( created, exists() );
+ }
+
+}
@@ -0,0 +1,37 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.integrationtests.nexus4955;
+
+import java.io.File;
+
+import org.sonatype.nexus.integrationtests.AbstractNexusIntegrationTest;
+import org.testng.annotations.Test;
+
+/**
+ * try to upload (deploy it) a file like "id" (no extension, just file name "id") into repo, nexus will die, it was
+ * reported by user on mailing list
+ *
+ * @author Marvin Froeder ( velo at sonatype.com )
+ */
+public class NEXUS4955UploadWOExtensionIT
+ extends AbstractNexusIntegrationTest
+{
+ @Test
+ public void deploy()
+ throws Exception
+ {
+ File file = getTestFile( "content.txt" );
+ getDeployUtils().deployWithWagon( "http", getRepositoryUrl( REPO_TEST_HARNESS_REPO ), file,
+ "nxcm4955/test/1.0/id" );
+ }
+}