summaryrefslogtreecommitdiff
path: root/spec/unit/file_system
AgeCommit message (Collapse)AuthorFilesLines
2014-08-19(PUP-3030) confine uniquefile unlink testsChris Price1-20/+24
Two of the new tests re: Uniquefile are not compatible with windows. (In the ruby source tree, they are skipped on windows.) This commit confines them to only run on unix.
2014-08-18(PUP-3030) Add Uniquefile tests, ported from Ruby sourceChris Price1-0/+132
This commit adds additional tests for the Uniquefile class. The new tests are ported from the Ruby 1.9.3 source code for the built-in `Tempfile` class, since that is what our `Uniquefile` implementation is based on. See: https://github.com/ruby/ruby/blob/v1_9_3_547/test/test_tempfile.rb
2014-08-18(PUP-3030) Rename P::F::Tempfile to UniquefileChris Price1-6/+6
Since the new implementation of Puppet::FileSystem::Tempfile is not trying to manage the deletion of files created through it, the name was misleading. This commit simply changes the name to Uniquefile to try to make it a bit more obvious that it is not responsible for deleting the files.
2014-01-23(PUP-1118) List environments from a directoryAndrew Parker1-504/+0
This starts the process of creating a Puppet::Environments::Directory that will find environments from a particular directory. The directory has sub-directories, where each sub-directory name is the environment name.
2014-01-15Merge branch 'pr/2168'Peter Huene1-0/+18
* pr/2168: (PUP-1150) Fix race condition in Puppet::Util::Lockfile. This closes GH-2168.
2014-01-15(PUP-1150) Fix race condition in Puppet::Util::Lockfile.Glenn Pratt1-0/+18
Before this commit, Puppet::Util::Lockfile.lock called the locked? method before opening the @lockfile for write. Checking that the file doesn't exist and creating the file were not an atomic operation, which allowed two processes to detect that the file didn't exist and open it for write simultaneously. This commit adds and used Puppet::FileSystem::exclusive_create wrapper that sets the following options: * File:CREAT - Creates the file if it doesn't exist. * File:EXCL - Fails if the file does exist. * File:WRONLY - Opens the file for write only. File:EXCL is the important option, callers will recieve an Exception if the file exists, meaning another process has acquired the lock. If the file doesn't exist it will be created atomically, so other another caller cannot create the file in the gap.
2014-01-14(maint) Fix unused argument and variable in file_spec.rbGlenn Pratt1-1/+1
2014-01-10(PUP-716) Assert path before making stat expectationJosh Partlow1-1/+1
File system changes ensure that Strings get converted to Pathnames; so the Puppet::Util::Windows::File.stat call needs to expect a Pathname now.
2014-01-06(PUP-716) Remove references to FileSystem::File in non codeHenrik Lindberg1-1/+0
2014-01-06(PUP-716) Refactor tempfile_spec after FileSystem API changeHenrik Lindberg1-3/+3
2014-01-06(PUP-716) Refactor and mae file_system/file_spec greenHenrik Lindberg1-163/+161
This refactors the file_system/file_spec to comply with the new API. Several problems found with the implementation. * Bad include of memory_impl * facade methods did not relay to _impl * assert_path did not consider objects coercable to string (e.g.watched file)
2013-12-20(PUP-1133) Cleanup Windows symlinkEthan J. Brown1-0/+3
- Windows symlinks, when targeted at directories, do not get cleaned up if not unlinked, even when going through the global tmpfile
2013-11-20(#7244) Add a Tempfile.open that unlinks tempfile earlyJosh Partlow1-0/+48
Tempfile.open, at least under Ruby 1.8, only does a File#close; File#unlink is deferred to a lambda that executes in a finalizer when the file is garbage collected. This can lead to issues, as it did with Puppet::SSL::AutosignCommand code, where root opens a tempfile, and the finalizer doesn't happen until after we've dropped privileges...leading to an almost impossible to find permission failure. This commit adds a Puppet::FileSystem::Tempfile with an open that ensures we close and unlink before returning to the caller. And we update the autosign_command code to use it.
2013-11-14(#19447) Fall back to stat if we don't support symlinksJosh Cooper1-2/+4
Previously, when managing a file with a source parameter pointing to a local file, the file resource and file serving code would try to call `Puppet::FileSystem::File.lstat`, without knowing if the path referred to a link or not. In other words, the method can be called on things other than a link, and shouldn't fail when symlinks aren't supported, i.e. windows 2003. We could change all of the callers to check if the path is a link and then only call `lstat`, but that seemed more risky. This commit just changes the windows `lstat` method to fall back to stat in the 2003 case.
2013-11-14(#19447) check Puppet.features.manages_symlinks?Ethan J. Brown1-2/+2
- Replace calls to the specific :file provider with the global Puppet.features call
2013-11-14(#19447) Puppet::FileSystem::File Windows symlinkEthan J. Brown1-0/+386
- Windows symlink support has been added to exist?, symlink, symlink?, readlink, stat, and lstat. This overrides any usage of Ruby File or FileTest classes which are completely borked on Windows. - :manages_symlinks feature of the file provider is enabled with a check against Puppet.features.manages_symlinks? which checks for the existence of the CreateSymbolicLink call in kernel32.dll - FFI wrappers for Win32 API calls CreateSymbolicLink, CreateFile, GetFileAttributes, DeviceIoControl and CloseHandle added to windows/file NOTE: The DeviceIoControl method of resolving symlinks was used instead of GetFinalPathNameByHandle, which is known to misbehave with UNC paths - Any tests against :manages_symlinks feature are automatically turned on for Windows, increasing test count by approximately 42 new tests - Removed a few symlink tests that were confined to any OS other than Windows since they must now be adjusted to run on Windows versions that we know support symlinks - Updated symlink documentation based on ileUtils.symlink behavior
2013-10-30(Maint) Reformat and remove debugging messageAndrew Parker1-7/+6
The previous commit contained bad formatting since I wrote it on a machine with a stock vim (tabs and wrong indentation). This also removes a forgotten debugging message in a spec.
2013-10-30(#693) Update file handling to work on SolarisAndrew Parker1-4/+25
It appears that solaris has different file semantics from OSX and Linux. * flock() is allowed on the same file from the same process. On linux this ends up with a block of the second invocation of flock(). * flock() is not allowed on a file that is opened for read-only. * fopen() with "a" causes a read to occur at the end of the file. On linux the read is at the beginning of the file.
2013-10-28(Maint) Provide a timeout when trying to aquire a file lockAndrew Parker1-0/+12
It is possible that the process is never able to aquire a lock. In that case we don't want to block the process forever. There was also a horrible performance characteristic from doing a busy loop while waiting for the lock.
2013-10-25(Maint) Exclude `fork` based tests on WindowsJosh Cooper1-2/+3
We have to skip these tests on Windows because fork is not supported.
2013-10-23(Maint) Allow File to work on ruby 1.8 and 1.9Andrew Parker1-6/+7
Ruby 1.8 does not have the same ::File constants as ruby 1.9 (specifically it did not have ::File::BINARY). Instead of using those constants, the File abstraction will instead use the character-based file modes (r, r+, w, w+, wb, etc.). Pathname on ruby 1.8 also does not support binread. To deal with this, the File now has 2 subclasses File18 and File19 to handle the differences on the different systems. The File::new method is now a factory for the appropriate subclass.
2013-10-22(Maint) Introduce File abstractionAndrew Parker1-0/+64
Over time we have accumulated various file manipulation operations that either deal with platform differences of the standard ruby calls or introduce more useful abstractions for us on top of the ruby calls. That code has not had a good place to live. Sometimes it appeared on certain classes, never to be found for use in other areas of the code. Other times it has been added to the ever growing Puppet::Util mess. This introduces Puppet::FileSystem::File, which should be used as our abstraction over ruby's File. We should strive to have it keep a minimal interface that is geared towards the operations that puppet performs on files. Inspiration for how to grow it should come, primarily, from uses found in the puppet codebase as well as from other FS abstraction systems (such as EFS from eclipse). This iteration of Puppet::FileSystem::File grew from the file operations that were done in the filebucket code.
2013-08-06(maint) Fix windows test for embedded '..' in pathJosh Partlow1-4/+4
Was calling relative with an absolute url. Moved to the absolute section.
2013-08-06(#21971) Allow paths that contain .. as part of a nameJosh Partlow1-0/+16
The PathPattern code was incorrectly flagging paths like /tmp/foo..bar as being directory traversals. This updates that to exclude those names by checking each path component separately instead of looking at the path as a whole. In addition this fixes up the error reporting about these kinds of errors in Puppet::Module by creating the absolute PathPattern for the manifests directory of the module at initialization time, so that any errors from it are not swallowed by the error handling for the relative path searching of manifests. This also removed some duplicate handling of init.pp and init.rb where in the case of having no pattern to search for the init files were returned twice and also seemed to be loaded twice. This does not remove the behavior in which the init.pp and rb files are *always* returned when they exist, because that seems to be explicit behavior added for issue #4220.
2013-08-06(#21971) Create system for safely dealing with path patternsAndrew Parker1-0/+122
Correctly checking that a given string is safe to use for looking for files on the filesystem is tricky. This adds a class called Puppet::FileSystem::PathPattern that encapsulates a validated path pattern free of defects such as directory traversal '..' entries and zero byte delimeters. This is then used to protect finding manifest files in modules.