Giter Site home page Giter Site logo

Comments (3)

kjzz avatar kjzz commented on July 26, 2024

Hey @schomatis ,i am doing for this bug now.But i want to know that what i should do when
if cur+bs <= offset?

from go-unixfs.

schomatis avatar schomatis commented on July 26, 2024

I'm not really sure but I think we should replicate the logic from Seek,

if int64(newoffset) > fisize {
if err := dm.expandSparse(int64(newoffset) - fisize); err != nil {
return 0, err
}
}

where, if the offset is bigger than the file length, we expand the file DAG; copying that logic into the Sync function,

// overwrite existing dag nodes
thisc, err := dm.modifyDag(dm.curNode, dm.writeStart)
if err != nil {
return err
}
dm.curNode, err = dm.dagserv.Get(dm.ctx, thisc)
if err != nil {
return err
}
// need to write past end of current dag
if dm.wrBuf.Len() > 0 {
dm.curNode, err = dm.appendData(dm.curNode, dm.splitter(dm.wrBuf))
if err != nil {
return err
}
err = dm.dagserv.Add(dm.ctx, dm.curNode)
if err != nil {
return err
}
}

Before appending the data, and after modifyDag has been called, we should check if writeStart (the offset where we should start writing) is bigger the the file size, and in that case (as before) also expand the file before appending.

Right now if you have to write to the offset 4 in a file of length 0 modifyDag will do nothing (which is correct, there is no existing space to overwrite) and Sync will just append the write buffer to the end of the file, that in this case would be the offset 0 (since that's the end of the file) which is incorrect, we want to fill the file DAG with zeros between the end of the DAG (offset 0) and the place to start writing (offset 4) and only then append the write data.

You'll need to check this patch against the go-ipfs tests, that means using gx-go link to make go-ipfs use your modified go-unixfs and not the Gx version.

from go-unixfs.

schomatis avatar schomatis commented on July 26, 2024

Fixed by #33.

from go-unixfs.

Related Issues (20)

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.