Skip to content

Commit

Permalink
Don't create a bag when validating issue #21
Browse files Browse the repository at this point in the history
  • Loading branch information
little9 committed Oct 31, 2016
1 parent c4b0d34 commit d17133b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 11 additions & 5 deletions bin/bagit
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@ DOCOPT

begin
opts = Docopt::docopt(doc, version: BagIt::VERSION)

bag = BagIt::Bag.new(opts['BAGPATH'])

unless opts['validate']
bag = BagIt::Bag.new(opts['BAGPATH'])
end
#####################################
# commands that don't alter the bag #
#####################################
if opts['validate']
if opts['--oxum']
logger.info(bag.valid_oxum?.to_s)
if File.exists?(opts['BAGPATH']+'/bag-info.txt') && File.directory?(opts['BAGPATH']+'/data') && File.exists?(opts['BAGPATH']+'/manifest-md5.txt') || File.exists?(opts['BAGPATH']+'/manifest-sha1.txt')
bag = BagIt::Bag.new(opts['BAGPATH'])
if opts['--oxum']
logger.info(bag.valid_oxum?.to_s)
else
logger.info(bag.valid?.to_s)
end
else
logger.info(bag.valid?.to_s)
logger.error("Not a valid bag")
end
# validation commands MUST NOT change manifest or bag-info files
exit
Expand Down
6 changes: 4 additions & 2 deletions lib/bagit/bag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ class Bag
include Fetch # fetch related functionality

# Make a new Bag based at path
def initialize(path, info={})
def initialize(path, info={}, create=false)


@bag_dir = path

# make the dir structure if it doesn't exist
FileUtils::mkdir bag_dir unless File.directory? bag_dir
FileUtils::mkdir data_dir unless File.directory? data_dir
Expand All @@ -31,6 +32,7 @@ def initialize(path, info={})
unless File.exist? bag_info_txt_file
write_bag_info(info)
end

end

# Return the path to the data directory
Expand Down

0 comments on commit d17133b

Please sign in to comment.