示例#1
0
 public OpenChunk(Chunk c, FileStream f)
 {
     this.chunk = c;
     this.file = f;
 }
 /**
  * it seemed to be getting too complicated trying to work "is full" into
  * the logic of add(), so instead that is taken care of here.  this only
  * happens once, before mount time, so the cost is trivial
  */
 private void addToSubdir(Chunk c)
 {
     if (currentSubdir == null) return;
     long total = c.LogicalLength;
     foreach (Chunk already in currentSubdir) total += already.LogicalLength;
     if (total > chunkSize) newSubdir();
     currentSubdir.Add(c);
 }
示例#3
0
 // add a file to the configuration, with running chunk sizes if set
 public bool add(string fileName)
 {
     lock (myLock)
     {
         FileInfo fi         = new FileInfo(fileName);
         long     fsize      = fi.Length;
         long     deductible = ((totalBytes + deductedBytes) % chunkSize);
         // don't make a too-small first chunk
         if (deductible > ((1.0 - this.Config.MinimumChunk) * chunkSize))
         {
             deductedBytes += (chunkSize - deductible);
             deductible     = 0;
         }
         //// dont make a too-small last chunk ??????? [the calc is wrong, but so is the concept... doing this leads to possible very-short fills]
         //else if ((fsize + deductible) % chunkSize < (this.Config.MinimumChunk * chunkSize))
         //{
         //    deductedBytes += deductible;
         //    deductible = 0;
         //}
         chunks = (int)((deductible + fsize) / chunkSize);
         if (((chunks * chunkSize) - deductible) < fsize)
         {
             chunks += 1;
         }
         debug("exposing file " + fileName + " in chunks of " + chunkSize + "(total of " + chunks + ")");
         for (int i = 0; i < chunks; i++)
         {
             long offset = (i * chunkSize) - deductible;
             long length;
             if (i == 0)
             {
                 offset = 0;
                 length = chunkSize - deductible;
                 if (length > fsize)
                 {
                     length = fsize;
                 }
             }
             else if (i + 1 == chunks)
             {
                 length = (fsize + deductible) - (i * chunkSize);
             }
             else
             {
                 length = chunkSize;
             }
             if (Config.UseExtension && Config.SmartChunk && i + 1 < chunks)
             {
                 IFileChunkHelper ifh = FileChunkHelperFactory.GetInstance(fileName);
                 if (ifh != null)
                 {
                     long suggested = (ifh.LocateChunkEndPoint(fileName, offset + length));
                     if (suggested < (offset + length))
                     {
                         long delta = (offset + length) - suggested;
                         length        -= delta;
                         deductible    += delta;
                         deductedBytes += delta;
                     }
                 }
             }
             Chunk c = new Chunk(fileName, offset, length, i + 1, chunks, Config.UseExtension);
             MyDirectory.Add(c.getFileName(), c);
             orderedChunks.Add(c);
             //if (currentSubdir != null) currentSubdir.Add(c);
             addToSubdir(c);
             debug("chunk added: " + c.getFileName());
             totalBytes += c.LogicalLength;
         }
         return(chunks >= 1);
     }
 }
        // add a file to the configuration, with running chunk sizes if set
        public bool add(string fileName)
        {
            lock (myLock)
            {
                FileInfo fi = new FileInfo(fileName);
                long fsize = fi.Length;
                long deductible = ((totalBytes+deductedBytes) % chunkSize);
                // don't make a too-small first chunk
                if (deductible > ((1.0-this.Config.MinimumChunk) * chunkSize))
                {
                    deductedBytes += (chunkSize-deductible);
                    deductible = 0;
                }
                //// dont make a too-small last chunk ??????? [the calc is wrong, but so is the concept... doing this leads to possible very-short fills]
                //else if ((fsize + deductible) % chunkSize < (this.Config.MinimumChunk * chunkSize))
                //{
                //    deductedBytes += deductible;
                //    deductible = 0;
                //}
                chunks = (int)((deductible+fsize) / chunkSize);
                if (((chunks * chunkSize)-deductible) < fsize) chunks += 1;
                debug("exposing file " + fileName + " in chunks of " + chunkSize + "(total of " + chunks + ")");
                for (int i = 0; i < chunks; i++)
                {
                    long offset = (i * chunkSize) - deductible;
                    long length;
                    if (i == 0)
                    {
                        offset = 0;
                        length = chunkSize - deductible;
                        if (length > fsize)
                        {
                            length = fsize;
                        }
                    }
                    else if (i + 1 == chunks)
                    {
                        length = (fsize + deductible) - (i * chunkSize);
                    }
                    else
                    {
                        length = chunkSize;
                    }
                    if (Config.UseExtension && Config.SmartChunk && i + 1 < chunks)
                    {
                        IFileChunkHelper ifh = FileChunkHelperFactory.GetInstance(fileName);
                        if (ifh != null)
                        {
                            long suggested = (ifh.LocateChunkEndPoint(fileName, offset+length));
                            if (suggested < (offset+length))
                            {
                                long delta = (offset + length) - suggested;
                                length -= delta;
                                deductible += delta;
                                deductedBytes += delta;
                            }
                        }

                    }
                    Chunk c = new Chunk(fileName, offset, length, i + 1, chunks, Config.UseExtension);
                    MyDirectory.Add(c.getFileName(), c);
                    orderedChunks.Add(c);
                    //if (currentSubdir != null) currentSubdir.Add(c);
                    addToSubdir(c);
                    debug("chunk added: " + c.getFileName());
                    totalBytes += c.LogicalLength;
                }
                return (chunks >= 1);
            }
        }