Commit Graph
218 Commits
Author SHA1 Message Date
Daniel Trebbien aa799e39ad [JENKINS-49971] Fix a race condition in Util.loadFile() (#3225)
* Fix a race condition in Util.loadFile()

If the file is deleted in between when its existence is checked and the
file is opened for reading, then the method will fail to return an empty
string.

* Switch to using FileUtils.readFileToString()

(cherry picked from commit aaae71af4b)
2018-03-25 20:17:21 +02:00
Daniel Trebbien e798f64854 [JENKINS-49112] Revert use of Files.newBufferedReader() in Util.loadFile() (#3259)
* [JENKINS-49112] Revert use of Files.newBufferedReader() in Util.loadFile()

This partially reverts 67076834a2.

* Restore the use of StringBuilder and reading into buf
2018-01-26 18:35:20 +01:00
Daniel Trebbien e8c86a374f Use fileToPath() (#3219)
* Use fileToPath()

This is a follow-up to PR 3210 on GitHub. See:
https://github.com/jenkinsci/jenkins/pull/3210#discussion_r160045107

* Switch two File.toPath() calls to Util.fileToPath()

* Delete an unused import
2018-01-09 21:21:59 +01:00
Daniel Trebbien 67076834a2 Switch to calling Files.newBufferedReader
These changes were suggested by Extra Hints for NetBeans IDE:
http://plugins.netbeans.org/plugin/73447/
2017-12-27 19:45:30 -08:00
Devin Nusbaum 1270ba3b40 [JENKINS-48405] Use NIO in tryOnceDeleteFile and makeWritable (#3169)
* Use NIO in tryOnceDeleteFile and makeWritable

* Don't try to set PosixFileAttributes on Windows

* Do not create arbitrary exceptions in makeWritable to fix test failures on Windows

* Remove unhelpful layer of exception wrapping

* Add test exercising Util#makeWritable in Util#tryOnceDeleteFile

* Add test for deleting a non-existant file

* Return early if changing permissions with NIO succeeds
2017-12-16 09:23:41 +01:00
Devin Nusbaum fdccc0e838 [JENKINS-36088] Use NIO implementations of chmod and mode by default (#3135)
* Use NIO for FilePath#chmod and IOUtils#mode

* Add tests for NIO mode and chmod implementations

* Add test, remove new method, and update JavaDoc

* Provide system property to use native implementations of chmod and mode

* Revert unrelated whitespace modification

* Don't remove exception from throws and put imports in original location

* Fix broken JavaDoc links

* Ignore file type bits (above 0o7777) in Util#modeToPermission

* Use octal for constants and don't include file type bits

* Revert unnecessary changes to TarArchiverTest

* Add assertion that non-permission bits are ignored by chmod

* Use NIO copy with StandardCopyOption.COPY_ATTRIBUTES in copyToWithPermissions where possible

* Catch InvalidPathException and convert it to IOException

* Create utility method for File#toPath and use File#createDirectories after review

* Remove useless calls to toAbsolutePath and getAbsoluteFile

* Fix typos and use octal for constant after review

* Add test for behavior of copyToWithPermission with special bits
2017-12-01 10:01:34 +03:00
Devin Nusbaum 52fa4d90b9 [JENKINS-39179] [JENKINS-36088] Always use NIO to create and detect symbolic links and Windows junctions (#3133)
* Always use NIO to detect symlinks

* Make assertion failure message consistent

* Catch NoSuchFileException to keep tests passing

* Make method name more specific and simlify assumption

* Remove obsolete comment and reword the main comment in isSymlink

* Deprecate Kernel32Util#isJunctionOrSymlink

* Use assumptions for junction creation and add messages to assumptions

* Replace deprecated code with recommended alternative

* Add comment explaining call to DosFileAttributes#isOther

* Do not fall back to native code when creating symlinks

* Log FileSystemExceptions when creating symbolic links

* Catch InvalidPathException and rethrow as IOException

* Deprecate Kernel32Utils#createSymbolicLink and #getWin32FileAttributes

* Preserve original logging behavior on Windows and remove useless call to Util#displayIOException
2017-11-16 17:08:10 +01:00
Jesse Glick 6a4d800091 [JENKINS-44657] Noting when #2932 was merged. 2017-09-28 10:44:18 -04:00
Robert Sandell 3adfed4b06 [JENKINS-44657] Move sub-job's buildsdir when outside of itemrootdir (#2932)
* A test to verify JENKINS-44657 is working in core

* [JENKINS-44657] Move sub-job's buildsdir when outside of itemrootdir.

* [JENKINS-44657] Fix UsageStatisticsTest

Because we've added a test dependency that affects it.

* [JENKINS-44657] Normalize the path before comparing

* [JENKINS-44657] Use MockFolder instead of folders-plugin

for tests

* [JENKINS-44657] Document and annotate isDefaultBuildDir

* [JENKINS-44657] isDescendant doesn't throw IOException any more

* [JENKINS-44657] catch InvalidPathException and rethrow as IOException
2017-09-23 22:59:39 +03:00
Stephen Connolly 3871d7778e [JENKINS-43531] Plugins may not be expecting InvalidPathException
- Plugins should really be expecting it, but as historically they have not, may as well convert to IOE for them
2017-04-19 14:04:33 +01:00
Jesse Glick 23cb13aad0 Clean up usages of IOUtils.closeQuietly and related calls (#2830)
* Clean up usages of IOUtils.closeQuietly and related calls predating Java 7.

* Review comments from @oleg-nenashev.

* Noticed another place where try-with-resources would protect against a potential leak.
2017-04-08 00:41:27 +02:00
Stephen Connolly f0cd7ae8ff [JENKINS-42934] Avoid using new FileInputStream / new FileOutputStream 2017-03-20 12:50:46 +00:00
James Nord b6234721c1 kill those pesky hudson temp files 2017-03-06 17:34:16 +00:00
Jesse Glick 76aa0727f0 Functions.printStackTrace utility method. 2016-12-12 17:56:24 -05:00
Jesse Glick 24aa20635d Replaced other usages of printStackTrace. 2016-12-12 16:44:10 -05:00
Baptiste Mathus 5588df315d Add @since on Util.isSafeToRedirectTo() 2016-11-09 09:36:52 +01:00
Daniel Beck 72cb842b6c Cleaning up @since TODO / @since XXX 2016-10-15 23:22:20 +02:00
Oliver Gondža 7f6f495f86 Avoid deprecated findbugs annotations (#2144)
* Avoid deprecated findbugs annotations

* One more forgotten annotation
2016-10-15 12:53:56 -07:00
Nicolas De Loof 7b39424495 rely on try-with-resources 2016-10-03 15:12:48 +02:00
dbroady1 f4edf91782 [JENKINS-29956] Test Windows junctions before Java 7 symlink (#1787)
* Test Windows junctions before Java 7 symlink

Apparently Java 7 (and later) do not count Windows junctions as
symlinks.  When you drill down into the BasicFileAttributes structure,
reparse points are only counted under isOther.  So, since we already
have code that properly detects Windows Junctions, let's use that first
and then fallback to the Java 7 code.

* Add comment for change & link bug.

* Add test case

* Switch to Functions.isWindows().

* Use non-deprecated APIs for tmp file/dir mgmt

* Add better debugging.

* Allow spaces in junction name & dir name.

To do that, it was easier to use ProcessBuilder vs building up the correct
string in code to send to cmd.exe.

Also, I'll note that according to http://ss64.com/nt/syntax-internal.html,
mklink is in internal cmd.exe command.  So, it must be invoked through
"cmd.exe /c" for it to work.

* Remove comment mentioning bug number.

* Remove debugging output, per Baptiste's request

* Add newline at end of file.

* Make sure that the junction was removed.

* Use assertEquals to show retcode of Process.waitFor.

* Fix compilation errors by importing functions
2016-08-22 15:21:33 +02:00
Oleg Nenashev 96c97860b0 [FIXED JENKINS-37332] - Prevent File descriptor leaks when reading manifests from JARs (#2516)
* [JENKINS-37332] - Improve diagnostics of non-closed streams during reading of the manifests in PluginManager

* [JENKINS-37332] - Leakless processing of JarUrlConnection during Manifest parsing

* [JENKINS-37332] - Also implement leak-safe method for retrieving file modification date

* [JENKINS-37332] - Add spotcheck methods for manifest file access + Javadoc

* [JENKINS-37332] - Also test multi-line and empty attributes in the test
2016-08-21 00:00:41 +02:00
Oleg Nenashev 3c31cb9692 FindBugs: Suppress DM_GC in hudson.Util#pauseBetweenDeletes(), because it's a desired behavior for custom setting 2016-07-16 02:16:50 +03:00
Pavel Janousek b21ab921de [JENKINS-35570] List of computer's names extracted to Util (#2408)
* [JENKINS-35570] List of computer's names extracted to Util
2016-07-12 09:13:33 +02:00
Oleg Nenashev 1d2b15173c [JENKINS-34854] - Migrate missing settings to SystemProperties (#2362)
* [JENKINS-34854] - Migrate missing Integer and Boolean properties to SystemProperties

* [JENKINS-34854] - API methods for Long variables

* [JENKINS-34854] - Migrate Long settings to SystemProperties

* [JENKINS-34854] - Leftover change (I should use Save All)

* [JENKINS-34854] - Some fixes in Long methods Javadoc and log messages
2016-05-21 09:36:18 +04:00
Oleg Nenashev ce8922bd74 Merge branch 'master' into JENKINS-34755
Conflicts:
	core/src/main/java/hudson/Util.java
	core/src/main/java/hudson/WebAppMain.java
	core/src/main/java/hudson/model/Item.java
	core/src/main/java/hudson/model/Queue.java
	core/src/main/java/hudson/model/UpdateCenter.java
	core/src/main/java/hudson/security/csrf/DefaultCrumbIssuer.java
	core/src/main/java/hudson/slaves/NodeProvisioner.java
	core/src/main/java/jenkins/model/Jenkins.java
	core/src/main/java/jenkins/slaves/NioChannelSelector.java
	core/src/main/java/jenkins/util/xml/XMLUtils.java
2016-05-12 12:05:24 +02:00
Jesse Glick c2d0a5778e Merge commit '97a0fa0d036b9d3873c9b269123020a42e7ee3e9' into security-master 2016-05-11 12:07:25 -04:00
Daniel Beck 240405dfc3 Merge pull request #2026 from pjdarton/fix_jenkins_15331
[FIX JENKINS-15331] Windows file locking workaround
2016-05-04 01:32:27 +02:00
Jesse Glick 888ca85784 Merge branch 'security-stable-1.651' into security-master 2016-04-28 17:38:40 -04:00
Jesse Glick 11120802c1 Merge branch 'security-stable-1.625' into security-stable-1.642 2016-04-28 17:37:52 -04:00
Jesse Glick c88268d870 Merge branch 'security-stable-1.609' into security-stable-1.625 2016-04-28 17:36:42 -04:00
Daniel Beck e6efae7d0d [SECURITY-276] Better method name, add tests 2016-04-27 13:51:10 +02:00
Daniel Beck 2ed0c046df [FIX SECURITY-276] Don't allow open redirect using scheme-rel. URL 2016-04-25 19:50:53 +02:00
Baptiste Mathus 99c43c8ccd Remove pre Java 7 reflection's based invocations
Simplify the code now the minimum version is Java 7.
2016-04-13 23:09:22 +02:00
Baptiste Mathus 8b3e4f43a2 Multi-catch refactoring when applicable 2016-04-12 10:17:42 +02:00
Peter Darton 879f0556e3 Renamed system property from ...deletionMax to ...maxFileDeletionRetries (as requested during code review). 2016-02-15 10:44:38 +00:00
Peter Darton 310c674762 FIXED JENKINS-15331 by changing Util.deleteContentsRecursive, Util.deleteFile and Util.deleteRecursive so that they can retry failed deletions.
The number of deletion attempts and the time it waits between deletes are configurable via system properties (like hudson.Util.noSymlink etc).
Util.DELETION_MAX is set by -Dhudson.Util.deletionMax.  Default is 3 attempts.
Util.WAIT_BETWEEN_DELETION_RETRIES is set by -Dhudson.Util.deletionRetryWait.  Defaults is 100 milliseconds.
Util.GC_AFTER_FAILED_DELETE is set by -Dhudson.Util.performGCOnFailedDelete.  Default is false.

Added unit-tests for new functionality.
2016-02-12 16:22:35 +00:00
Johannes Ernst 9303136c9d Incorporated pull request feedback:
* moved to jenkins.util.SystemProperties
* consistent naming getString/getInteger/getBoolean
* improved code formatting
Improved JavaDoc
2015-11-18 18:26:41 +00:00
Johannes Ernst 709fe5b9aa Allow setting of system properties from context.xml in addition to setting from command-line.
Accomplished by centralizing calls to System.getProperty(String) and related into new file SystemProperties.java.
There, we first check for existence of system property; if not, we look for property in context.xml
This is done for "application" properties (like hudson.DNSMultiCast.disabled) but not for java properties (like user.name)
2015-11-17 01:38:51 +00:00
Antonio Muñiz 89a0050cea [JENKINS-30002] Improve Util.isOverridden 2015-10-05 10:13:42 +02:00
David Hoover 1709ed3a2e Add @Deprecated annotations to things documented as @deprecated. 2015-04-19 14:50:12 -07:00
Stephen Connolly 77abe1d11c tidy up @since tags after merge 2015-03-20 16:56:53 +00:00
Stephen Connolly 1cb69f8cc0 Move isRelativePath to Util and use from hudson.model.Slave's descriptor 2015-03-19 13:56:38 +00:00
Daniel Beck daacb02057 [JENKINS-16184] Also escape greater-than character 2014-10-09 00:38:22 +02:00
Oleg Nenashev 6c2fffb248 Fixed annotations in hudson/Util.java according to the discussion with @jglick and @kutzi
Signed-off-by: Oleg Nenashev <o.v.nenashev@gmail.com>
2014-05-05 22:26:12 +04:00
Oleg Nenashev 48cc7e03d4 Annotate hudson.Util methods.
The change adds annotations for all methods inside the class. The initial idea - enforce checks of symlink methods to prevent NPEs on Windows platforms.

Signed-off-by: Oleg Nenashev <o.v.nenashev@gmail.com>
2014-05-04 12:39:02 +04:00
Marco Miller d0f84c2e53 [FIXED JENKINS-20610] symlink FileAlreadyExistsException
Retrying 3 times while waiting for 100 millis between retries (at
recreating symlink after "deleting" it). Ends up throwing FAE exception
if thrown for a 4th time in a row - as not much can be done at that
point. A warning is logged in that case, prior to throwing the last FAE.
2013-11-15 16:32:27 -05:00
Jesse Glick c2366eeda5 Updated a couple of comments referring to Java 5. 2013-11-15 08:46:14 -05:00
Jesse Glick 4825967fe3 Deleting code using @IgnoreJRERequirement for Java 5 compatibility. 2013-11-15 08:43:40 -05:00
Jesse Glick 15ac490af1 Now that we use Java 6, can finally deprecate IOException2. 2013-11-15 08:19:59 -05:00
Larry North 3376cf0158 [FIXED JENKINS-16660] Allow variable names with dots in bracketed references.
Given these <variable,value> mappings: <A,a> and <A.B,a-b>, $A.B would
evaluate to $a.B, as it currently does, and ${A.B} to a-b instead of the
current ${A.B}.

Existing ${A.B}-like references will break (not evaluate to ${A.B}) if
there actually is an A.B variable defined, which I think is very
unlikely.
2013-07-26 21:15:51 -07:00