GithubHelp home page GithubHelp logo

file-locker's Introduction

Locked File

Purpose

This is a project to get a good RAII class for locking a file for reading and writing. This is implemented in C++.

The Purpose of Locking Files

The main use of file locking is to stop someone writing to a file between you reading it and writing it back out changed. It also becomes important implementing databases and websites.

Contents

The main class in this repository is LockedFile. In the repository there is this class and some supporting error classes. There is also a comprehensive unit test.

Application

There is a sample application which uses the file locking. What this does is lock the files you give it on the command line.

Implementation Details

This repository is indended to be built using make and the Microsoft C++ compiler. This repository currently only works on windows.

Running Unit Test

The entire project is built and the test run, by typing

make test

This should give output which looks like this.

===============================================================================
utest_LockedFile::test_file_exists
===============================================================================

Pass: File should exist

===============================================================================
utest_LockedFile::test_non_existant_file
===============================================================================

Pass: File should not exist
Pass: This is not PathNotFoundError

===============================================================================
utest_LockedFile::test_file_write_lock
===============================================================================

Pass: File should lock ok.
Pass: Should not write correctly.
Pass: Should write correctly.

===============================================================================
utest_LockedFile::test_file_deletion
===============================================================================

Pass: Should be no error from LockedFile
Pass: Should not be able to delete locked file.
Pass: File shouldn't be locked any more.

===============================================================================
utest_LockedFile::test_nested_locks
===============================================================================

Pass: First lock should work.
Pass: Second lock should not work.
Pass: This is not FileInUseError
Pass: Third lock should work.

Building the Application

It is built using

make

in the application directory. The executable is found under exe.

Implementation Problems

  • The dependencies in the makefile are not well set up. Somethimes if you change a header you need to manually remake other files (or make -B) to get them to compile.
  • The reading and writing in LockedFile says nothing about encoding.

file-locker's People

Contributors

davidcorne avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.